我想单击导航中的子菜单,但在Selenium中不起作用。 浏览器打开,第一个菜单显示为选中状态,但菜单下拉菜单未打开,我得到了错误:在子菜单上单击时,元素不可见。 希望代码细节可以帮助您解决我的问题
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;
}
}