我想点击导航中的子菜单,但它在Selenium中不起作用。浏览器打开,第一个菜单显示为已选中,但菜单下拉列表未打开,我收到错误:元素在子菜单点击时不可见。我希望,Code详细信息可以帮助您找出问题所在
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
[TestMethod]
public void OpenPatEarningCode()
{
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
Actions action = new Actions(driver);
var Menu = wait.Until(ExpectedConditions.ElementIsVisible(By.Name("Menu")));
action.MoveToElement(Menu).Click().Build().Perform();
IWebElement FirstmenuAdmin = Menu.FindElement(By.Name("First Menu"));
action.MoveToElement(FirstmenuAdmin).Click().Build().Perform();
IWebElement SubmenuElement = new WebDriverWait(driver, TimeSpan.FromSeconds(5)).
Until(ExpectedConditions.ElementToBeClickable(By.Name("Sub Menu")));
action.MoveToElement(SubmenuElement).Click().Build().Perform();
}
catch (Exception)
{
throw;
}
}
[TestMethod]
public void OpenPatEarningCode()
{
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
Actions action = new Actions(driver);
var Menu = wait.Until(ExpectedConditions.ElementIsVisible(By.Name("Menu")));
action.MoveToElement(Menu).Build().Perform();
IWebElement FirstmenuAdmin = wait.Until(ExpectedConditions.ElementIsVisible(By.Name("First Menu")));
action.MoveToElement(FirstmenuAdmin).Build().Perform();
IWebElement SubmenuElement = wait.Until(ExpectedConditions.ElementToBeClickable(By.Name("Sub Menu")));
SubmenuElement.Click();
}
catch (Exception)
{
throw;
}
}