0

I am automating a web page that essentially has a button which, each time it is pressed, creates a new text field. I am using the FindBy annotation with PageFactory to find the list of text fields.

I have a synchronization problem when I press the button several times, thus creating several text fields, and then try to write into one of them. Stepping through the debugger it works fine, but out of the debugger there is a delay before the FindBy finds all the text fields. My current workaround performs sleeps until the required number of text fields are found but I find this quite unsatisfactory. Any suggestions how the synchronization could best be done?

@FindBy(how= How.XPATH, using="//*[contains(@id, 'TextField')]")
private List<WebElement> textFields;
:
:
public void enterText(Integer index, String text){
    int attempts = 0;
    // Check every 10th of a second for 10 seconds if all the textFields have been found 
    while ((textFields.size() <= index) && attempts < 100){
        Thread.sleep(100);
    }

    textFields.get(index).sendKeys("blah blah");

}
1

1 Answer 1

1

First of all use Implicit wait for all element present in script. This wait is wait for all element present in the script

  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Initiate above just after get.("URL");

Now for specific element which need additional time you can use below code:-

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

Refer below:-

http://toolsqa.com/selenium-webdriver/wait-commands/

Hope it will help you :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.