所以我已經堅持了一段時間了。我有一個元素id=nextButton。我需要能夠多次點擊它。該程序如下所示:
Page1 -> nextButton.click() -> Page2 -> nextButton.click() -> ...
我對此不起作用的解決方案是:
第1頁
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
IWebElement nextButton = driver.FindElement(By.XPath("//*[@id=\"nextButton\"]"));
nextButton.Click();
第2頁
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
IWebElement nextButton2 = driver.FindElement(By.XPath("//*[@id=\"nextButton\"]"));
nextButton2.Click();
它沒有作業..它加載第1頁而不是點擊nextButton新頁面顯示并停止..
請幫助:)
uj5u.com熱心網友回復:
我想您需要在單擊 后延遲一些時間nextButton以使第一頁開始加載第二頁,然后等待nextButton在第二頁上可單擊,然后才能單擊它。
您的流程中發生的情況是:您嘗試nextButton在前一次點擊之后立即點擊,而您仍在第一頁上。
此代碼應該適合您:
using WaitHelpers = SeleniumExtras.WaitHelpers;
wait.Until(WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='nextButton']")).Click();
Thread.Sleep(500)
wait.Until(WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='nextButton']")).Click();
uj5u.com熱心網友回復:
謝謝@Prophet。我只是將 Thread.Sleep(500) 放在我的代碼之間,所以現在看起來像這樣:
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); IWebElement nextButton = driver.FindElement(By.XPath("//*[@id="nextButton"]")); nextButton.Click();
執行緒.睡眠(500);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); IWebElement nextButton2 = driver.FindElement(By.XPath("//*[@id="nextButton"]")); nextButton2.Click();
它正在作業:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/532178.html
