How to solve the problem of selenium waiting until page loads?

379    Asked by SarahLee in QA Testing , Asked on Oct 20, 2022

I run nearly 30-40 test cases twice a day. And every time some test case fails due to page load time. In fact I have explicitly mentioned Thread.sleep("2000"); wherever I feel it takes more time to load. But still some 5-6 test cases fail. How can I make my selenium wait until the page loads ?? And I got this exception


Starting ChromeDriver 2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed) on port 1828

              Only local connections are allowed.Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible(Session info: chrome=54.0.2840.99)

              (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)               Command duration or timeout: 36 milliseconds

              Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'System info: host: 'DESKTOP-LU4RI93', ip: '10.100.154.4', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'

              Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:UsersHRT 1~1AppDataLocalTempscoped_dir6436_32242}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.99, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]

              Session ID: dacb1d58627c657aa111d94eba60b81f


Answered by Ruth Lambert

You need to wait for an expected element to be shown on the page. This selenium wait until page loads will loop until either the timeout is reached or the element is found.


Reads:

http://toolsqa.com/selenium-webdriver/implicit-explicit-n-fluent-wait/

https://testing.googleblog.com/2009/06/my-selenium-tests-arent-stable.html



Your Answer

Interviews

Parent Categories