以下是我的硒測試用例的代碼片段,其中我使用select方法從下拉列表中選擇一個值。接下來的步驟是點擊提交。但是,當我嘗試點擊提交按鈕頁面不刷新(這將刷新相同的頁面),投擲selenium web驅動等到頁面刷新
element not clickable,StaleElementReference exception
。唯一適用於我的解決方案是thread.sleep()
。
我嘗試了所有的以下選項,但沒有運氣:(
explicit wait()
,wait.until(Exceptedcontions.visibility)
,element to be clickable()
等,試圖日網絡上的所有解決方案。
我不得不用在thread.sleep()
3-4次測試用例和我有大約100個測試用例花費了大量的時間
任何工作的解決方案,其中的網頁驅動程序等待,直到頁面被完全刷新,並在點擊提交按鈕之前DOM完全加載
@Test
@Timeout(group = Group.SLOW)
public void testProvider() throws InterruptedException {
proceedToProvider();
new Select(driver.findElement(By.id("searchId"))).selectByVisibleText("Search");
Thread.sleep(2000);
driver.findElement(By.id("btnSubmit")).click();
timeSplit("Search submitted");
下面是我看到的錯誤,當我使用其他解決方案。
org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (1289, 141). Other element would receive the click: (Session info: chrome=53.0.2785.116) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 168 milliseconds Build info: version: '2.49.1', revision: '808c23b0963853d375cbe54b90bbd052e2528a54', time: '2016-01-21 09:37:52' System info: host: 'ALAKASIMA01-W7L', ip: '10.145.45.233', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_73' Driver info: org.openqa.selenium.remote.RemoteWebDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\kasima01\AppData\Local\Temp\scoped_dir6628_12218}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=53.0.2785.116, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 8bf0b4cc7efc715015509f4be345d14d
@Test \t @Timeout(組= Group.SLOW) \t公共無效testProviderSearchDataShareOn()拋出InterruptedException的,ValidationException { \t \t proceedToProviderScreen(); \t \t new Select(driver.findElement(By.id(「searchId」)))。selectByVisibleText(「Search」); // \t \t Thread.sleep(2000); \t \t WaitForElementToLoad(「id」,「btnSubmit」,「20」);相同的元素不可點擊的錯誤。 – maddie
考慮一些元素覆蓋了你的目標元素。您需要移除屏障。 –