in Education by
I'm working on a Java Selenium-WebDriver. I added driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); and WebElement textbox = driver.findElement(By.id("textbox")); because my Applications takes a few seconds to load the User Interface. So I set 2 seconds implicit wait. but I got unable to locate element textbox Then I add Thread.sleep(2000); Now it works fine. Which one is a better way? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Basically, there are two types of waits and they are as follows: explicit wait and implicit wait. The code for the explicit wait is as follows: WebDriverWait.until(condition-that-finds-the-element); The code for the implicit wait is as follows: driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); You can analyze the difference in detail here. public WebElement fluentWait(final By locator) { Wait wait = new FluentWait(driver) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); WebElement foo = wait.until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(locator); } }); return foo; } Usage of fluentWait in your case will be something like the following: WebElement textbox = fluentWait(By.id("textbox")); Hope this helps! If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s online automation testing training!

Related questions

0 votes
    I have written tests with Selenium2/WebDriver and want to test if HTTP Request returns an HTTP 403 Forbidden. ... Selenium WebDriver? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    How to open a new tab in the existing Firefox browser using Selenium WebDriver (a.k.a. Selenium 2)? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I want to put value using webdriver, This is the command I am using driver.findElement(By.name("name")).sendKeys(" ... way to do so ? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am converting my selenium 1 code to selenium 2 and can't find any easy way to select a label in a ... ("//path_to_drop_down"); Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    In the HTML of a web app, there is the following code What is actually shown on the page is a string displaying ... . Any help? Thanks. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I use Selenium RC, for which the scroll command is selenium.getEval("scrollBy(0, 250)"); Now, I have started ... the command for it? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Could someone tell me whether Selenium is a good career option? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    I see this only in Chrome. The full error message reads: "org.openqa.selenium.WebDriverException: Element is not ... for scrolling. Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    We are using Selenium to automate our testing. Recently we have seen the majority of our users using Chrome. ... over Selenium? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a certain element that I can select with Selenium 1. Unfortunately, I need to click the parent element ... upwards with XPath? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am new in software testing and looking to enhance my knowledge. I want to know in detail about: What is ... answer here. Thanks! Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I use Selenium RC, for which the scroll command is selenium.getEval("scrollBy(0, 250)"); Now, I ... questions and answers pdf, Verbal Reasoning interview questions for beginners...
asked Oct 30, 2021 in Education by JackTerrance
0 votes
    Page scroll up or down in Selenium WebDriver (Selenium 2) using java I use Selenium RC, for which the scroll command ... using Selenium WebDriver , what will be the command for it?...
asked Nov 20, 2020 in Education by Editorial Staff
0 votes
    The semicolon (;) at the end of the code is the thing which is got me lost. private View. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    The semicolon (;) at the end of the code is the thing which is got me lost. private View. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
...