如何使用鼠标悬停单击硒中的子菜单



我想单击导航中的子菜单,但它在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;
}
}
[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;
}
}

相关内容

  • 没有找到相关文章

最新更新