简体   繁体   中英

Sendkeys query in selenium webdriver java

As part of my requirement, I need to fill 6 cells in a webpage, one after other. all these 6 cells are placed in the same row in a web page.

the code is as below:

driver.findElement(By.id("a")). sendKeys(Name, Keys.TAB);

WebDriverWait waiting2 = new WebDriverWait(driver, 50);
waiting2.until(ExpectedConditions.elementToBeClickable(By.id("b")));

driver.findElement(By.id("b")).sendKeys(Contact, Keys.TAB);
WebDriverWait waiting3 = new WebDriverWait(driver, 50);
waiting3.until(ExpectedConditions.elementToBeClickable(By.id("c")));

driver.findElement(By.id("c")).sendKeys(Address, Keys.TAB);

WebDriverWait waiting4 = new WebDriverWait(driver, 50);

waiting4.until(ExpectedConditions.elementToBeClickable(By.id("d")));

driver.findElement(By.id("d")).sendKeys(email, Keys.TAB);
WebDriverWait waiting5 = new WebDriverWait(driver, 50);
waiting5.until(ExpectedConditions.elementToBeClickable(By.id("e")));

driver.findElement(By.id("e")).sendKeys(Startdate,  Keys.TAB);

WebDriverWait waiting6 = new WebDriverWait(driver, 50);
waiting6.until(ExpectedConditions.elementToBeClickable(By.id("f")));

driver.findElement(By.id("f")).sendKeys(Enddate);

The Name, address, contact, startdate, end date are variables, which are getting data from a excel sheet. when I run this code, some times all the cells are getting filled as expected. sometimes only a few cells gets filled. that is for example cell1 and cells2 gets the values from excel sheet. And cells 3 remains blank. Again cell4 gets the value.

How to fill all the cells, one after other with out leaving any cell blank.

in short how to make code to move to the next cell only after filling the previous one?

Your problem will be solved if you use implicit wait and also you don't have to move to next text box, it automatically does for whichever element sendKes methods is being called. But you need to be careful If page refreshes when you move from one textfield to another, but even if it refreshes, implicit wait will resolve the problem. Use Implicit wait, you problem will surely be solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM