spa*_*bed 13
好的!所以我很感激帮助(我实际上看过那个帖子,但是.hover()类已被弃用了,我无法让它工作.但是,我确实找到了一个可靠的解决方法.
var phone = driver.FindElement(By.Id("phones"));
var phoneLi = phone.FindElements(By.TagName("li"));
Actions action = new Actions(driver);//simply my webdriver
action.MoveToElement(phoneLi[1]).Perform();//move to list element that needs to be hovered
var click = action.MoveToElement(phoneLi[1].FindElements(By.TagName("a"))[0];//move to actual button link after the 'Li' was hovered
click.Click();
click.Perform(); //not too sure why I needed to use both of these, but I did. Don't care, it works ;)
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
Run Code Online (Sandbox Code Playgroud)
此外,您还需要使用一对使用语句.
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Interactions.Internal;
using OpenQA.Selenium.Support.UI;
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!