C# 如何使用SeleniumWebDriver在不执行任何鼠标单击的情况下将鼠标移到隐藏菜单上?

C# 如何使用SeleniumWebDriver在不执行任何鼠标单击的情况下将鼠标移到隐藏菜单上?,c#,selenium-webdriver,automated-tests,C#,Selenium Webdriver,Automated Tests,如何使用selenium webdriver在不执行任何鼠标单击的情况下将鼠标悬停/悬停在隐藏菜单上 我正在测试的网站上有一个隐藏菜单,它只出现在鼠标悬停/上方。 注意:如果执行了任何单击,页面将被重定向,因此请在不单击的情况下建议解决方案 我试过: IWebDriver driver = new FirefoxDriver() Actions builder = new Actions(driver) builder.MoveToElement(driver.FindElement(By.Id

如何使用selenium webdriver在不执行任何鼠标单击的情况下将鼠标悬停/悬停在隐藏菜单上

我正在测试的网站上有一个隐藏菜单,它只出现在鼠标悬停/上方。 注意:如果执行了任何单击,页面将被重定向,因此请在不单击的情况下建议解决方案

我试过:

IWebDriver driver = new FirefoxDriver()
Actions builder = new Actions(driver)
builder.MoveToElement(driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")))
       .Click().Build().Perform();
试试这个

// this makes sure the element is visible before you try to do anything
// for slow loading pages
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(elementId)));

Actions action  = new Actions(driver);
action.MoveToElement(element).Perform();

是的,你贴的问题是关于工具提示的

执行鼠标悬停,然后捕获其属性值

仔细观察HTML代码手动将鼠标指针移动到元素上&观察隐藏文本的属性值

Actions builder = new Actions(driver)
builder.MoveToElement(driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")))
       .Click().Build().Perform();


String value=driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")).getAttribute("attribute value in which hidden text presents");

您需要使用-使用OpenQA.Selenium.Interactions

我只是想提一下,最后的解决办法可能是尝试javascript鼠标悬停模拟


各种语言的解决方案发布在这里:

Woah!我从来不知道如何使用TimeSpan类。谢谢然而,它仍然会在结尾处打开另一个浏览器窗口。我不明白你的意思