Stu*_*XXL 2 c# selenium qa webdriver selenium-webdriver
我有一个网站,顶部有一个 jQuery 幻灯片,上面有我想使用的所有语言的列表:http : //testing.bestshippers.com/net/index.aspx,滑块是“语言选择”按钮最佳。
我可以单击它,但是在尝试单击幻灯片内部的元素时出现错误。我相信这是因为在尝试选择它们之前我需要暂停几秒钟。可能是错的?我相对较新,但我已经阅读了有关 WebDriverWait 和改变焦点的各种内容。
//check spanish
driver.FindElement(By.XPath("//*[@id='openCloseWrap']/img")).Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
driver.FindElement(By.Id("ButtonSPFlag")).Click();
String check = driver.FindElement(By.XPath("html/body/form/div[5]/div/div[1]/div/p")).Text;
Console.Out.WriteLine(check);
Run Code Online (Sandbox Code Playgroud)
上面的代码单击 openCloseWrap(语言选择按钮),然后我尝试暂停几秒钟(100),然后尝试单击 SP 标志以更改语言。
任何人都能够为我的等待为什么不会暂停提供任何帮助?
您正在启动等待,但没有等待任何事情。你可能想要做类似的事情:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
// wait.Until(By.Id("ButtonSPFlag"));
IWebElement element = wait.Until(driver => driver.FindElement(By.Id("ButtonSPFlag")));
element.Click();
Run Code Online (Sandbox Code Playgroud)
或者,您可以设置隐式等待,但我会选择第一个。
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10108 次 |
最近记录: |