Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we make selenium webdriver to wait until user clicks on a webpage link at run-time without using implicit wait?

I am using Firefox driver with java and trying to scrape some data from a website. There is a human interaction involved in it and I have to ask the user to input a search string. And then accordingly user has to select which search result to open by analyzing with human eye. The effort is just to make few bits and pieces work faster through script.

My question is:

Can we make selenium webdriver to wait until user clicks on a webpage link at run-time without using implicit wait? I can not use implicit wait because the time for click may vary from few seconds to few minutes.

I am new to both java and selenium. Your help will be much appreciated.

- Thanks

like image 991
aks Avatar asked Jan 10 '14 04:01

aks


2 Answers

Selenium webdriver is a tool used to Automate tests on web based applications,which means even human interactions are automated.

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.

This means ,you cannot use this to wait for human interactions.But you can assume that the user is waiting for some link to appear and call click().

This can be achieved using Explicit wait.

An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code.

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("some_link")));
element.click();

The above code waits for 30 secs for the link to appear and to be clickable.

Refer this for more info.

like image 103
Amith Avatar answered Oct 07 '22 08:10

Amith


For sure you can. We use Selenium a lot as an assistant in getting some datas from websites.

When you have a process involving multiple steps, including opening website, login, choosing 54 parameters and need only 1 human interaction (resolving a captcha, for example), Selenium can automate those boring tasks and let the user concentrate on the one which is important.

What we do here, is to make a Swing dialog with an input field to get what the user want to enter, then the actual form submission is performed by Selenium. You can do the same thing with links, and you can ask the user to select a link to click on, and perform the actual click with webdriver.

The ExplicitWait method of Amith is also a good one. You can focus on what you expect after the user has clicked, and wait until this condition is realized

like image 41
Grooveek Avatar answered Oct 07 '22 09:10

Grooveek