我的代码是:
[TestMethod]
public void ActionClickAndHold()
{
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://jqueryui.com/selectable/");
driver.FindElement(By.Id("selectable")).Click();
System.Threading.Thread.Sleep(10000);
driver.SwitchTo().Frame(0);
ReadOnlyCollection<IWebElement> lstItems = driver.FindElements(By.XPath("//*[@id='selectable']/li[1]"));
Actions builder = new Actions(driver);
builder.ClickAndHold(lstItems[1])
.ClickAndHold(lstItems[3])
.Click()
.Perform();
driver.SwitchTo().DefaultContent();
}
它不起作用。它不会单击并保持在网格中。我在哪里知道自己的错误?
答案 0 :(得分:1)
实际上你会遇到错误的元素,请尝试如下: -
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://jqueryui.com/selectable/");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3))
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.ClassName("demo-frame")));
ReadOnlyCollection<IWebElement> lstItems = wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.CssSelector("#selectable li")));
builder.ClickAndHold(lstItems[1])
.ClickAndHold(lstItems[3])
.Click()
.Perform();
driver.SwitchTo().DefaultContent();
希望它有所帮助.. :)