Can I make selenium pause for input and resume on a trigger? Can I make selenium pause for input and resume on a trigger? selenium selenium

Can I make selenium pause for input and resume on a trigger?


Option 1:

This can be easily achieved using Explicit wait. Suppose you want to manually enter data in some field. You can make the selenium wait till the point where the field contains a value(Its "value" attribute is not empty). Ex:

WebDriverWait wait = new WebDriverWait(driver, 100);//whatever time you think is sufficient for manually entering the data.WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id(>someid>)));if(ExpectedConditions.attributeToBeNotEmpty(element,"value")){  //continue with the automation flow}

Option 2:

It is kinda hacky. What you can do is, At the beginning of the execution open another tab and then switch back to your original one, like this:

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");driver.switchTo().defaultContent();

Now execution will start and at the point where you want the script to stop for you to manually enter your data, retrieve all the tabs from selenium in an infinite loop like this-

for(int i =1;i>0;i++){ ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles()); if(tabs.size()==2) {  //keep checking for the point when the number of tabs becomes 1 again.  continue; } else {  break; }}//your rest of the automation code

The idea is to make selenium pause the execution(since it will be stuck in the loop) till the point where number of tabs again become 1. During this, you enter your data and close the empty tab so that the selenium can continue its execution.

You can also try this.


Note: I have used selenium via python, so solution reflects that.

Oh yeah. It's just a python script. Don't think of it in terms if selenium script. A python script can be easily made to wait for input.

print("Hi!. Script Started")# code to load webpage, automatically fill whatever can be enteredx = input("Waiting for manual date to be entered. Enter YES when done.")# Enter the data on page manually. Then come back to terminal and type YES and then press enter.if x == 'YES':    continue_script_here()else:    kill_script_or_something_else()


There are several waits available in selenium.

Implicit Wait: During Implicit wait if the Web Driver cannot find it immediately because of its availability, it will keep polling (around 250 milli seconds) the DOM to get the element. If the element is not available within the specified Time an NoSuchElementException will be raised. The default setting is zero. Once we set a time, the Web Driver waits for the period of the WebDriver object instance.

Explicit Wait: There can be instance when a particular element takes more than a minute to load. In that case you definitely not like to set a huge time to Implicit wait, as if you do this your browser will going to wait for the same time for every element.

To avoid that situation you can simply put a separate time on the required element only. By following this your browser implicit wait time would be short for every element and it would be large for specific element.

Fluent Wait: Let’s say you have an element which sometime appears in just 1 second and some time it takes minutes to appear. In that case it is better to use fluent wait, as this will try to find element again and again until it find it or until the final timer runs out.

https://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

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