{"id":6280,"date":"2020-01-13T04:49:14","date_gmt":"2020-01-13T04:49:14","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=6280"},"modified":"2024-12-07T14:53:32","modified_gmt":"2024-12-07T14:53:32","slug":"how-to-fix-webdriverwait-deprecated-message-in-selenium-tests","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-fix-webdriverwait-deprecated-message-in-selenium-tests\/","title":{"rendered":"How to fix WebDriverWait deprecated message in Selenium tests?"},"content":{"rendered":"<h2>How to fix WebDriverWait deprecated message in Selenium tests?<\/h2>\n<p>In this tutorial, we will see how to fix the <strong>WebDriverWait<\/strong> deprecated warning message in Selenium tests. The constructor WebDriverWait(WebDriver, long) is deprecated now in the Selenium framework.<\/p>\n<h3>Deprecated Code<\/h3>\n<p>So the declaration of web driver wait of this form would appear strikes in the test automation code.<\/p>\n<pre>WebDriverWait wait = new <del>WebDriverWait<\/del>(driver, 120);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The long parameter 120 is the timeout specified in seconds. This makes the driver instance to wait<\/p>\n<p>waiting until an expected condition is true or not null in the web tests.<\/p>\n<p>&nbsp;<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6281\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/WebDriverWait-dperecated-message.png\" alt=\"\" width=\"1530\" height=\"857\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/WebDriverWait-dperecated-message.png 1530w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/WebDriverWait-dperecated-message-300x168.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/WebDriverWait-dperecated-message-1024x574.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/WebDriverWait-dperecated-message-768x430.png 768w\" sizes=\"auto, (max-width: 1530px) 100vw, 1530px\" \/><\/h3>\n<p>&nbsp;<\/p>\n<h3>Fix<\/h3>\n<p>To fix the warning message, we need to pass the timeout as <strong>a Duration <\/strong>class. In most cases Duration class models time in seconds and in nanoseconds.<\/p>\n<p>To fix the selenium tests we should use:<\/p>\n<pre>WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120, 1));\r\n\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6287\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Duration-class.png\" alt=\"Duration class\" width=\"1726\" height=\"856\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Duration-class.png 1726w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Duration-class-300x149.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Duration-class-1024x508.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Duration-class-768x381.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Duration-class-1536x762.png 1536w\" sizes=\"auto, (max-width: 1726px) 100vw, 1726px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to fix WebDriverWait deprecated message in Selenium tests? In this tutorial, we will see how to fix the WebDriverWait deprecated warning message in Selenium tests. The constructor WebDriverWait(WebDriver, long) is deprecated now in the Selenium framework. Deprecated Code So the declaration of web driver wait of this form would appear strikes in the test [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[185],"tags":[214],"class_list":["post-6280","post","type-post","status-publish","format-standard","hentry","category-selenium","tag-selenium","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/6280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=6280"}],"version-history":[{"count":13,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/6280\/revisions"}],"predecessor-version":[{"id":26273,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/6280\/revisions\/26273"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=6280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=6280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=6280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}