Migration issue fix from Selenium1 to Selenium3

For migration, because the old system needs to run to new browser and keep test automation running normally, so facing new browser, csv command parse code also needs to be adjusted.

Below are some issues happened during testing, and solutions:

1. Because run too faster on v63
When WebDriverWait function can’t work for waiting time, we need to consider another directly simple way to wait element shows in page, but this way is not the best  solution, only for work.

try {
    Thread.sleep(seconds);
}
catch( Exception e) {
    e.printStackTrace();
}

Place the code before/after refresh/post… actions which need to slow down seconds.It often happened on click & type commands.

2. Element is not clickable issue

Due to element position can’t be displayed suitable position, the click action can’t do operation by another element obscured, so we need to adjust element position:

WebDriver driver=...;
WebElement element=...;
JavascriptExecutor executor = (JavascriptExecutor) driver;

int eleY = element.getLocation().y +/- offset; //down or up
int eleX = element.getLocation().x +/- offset; //right or left

executor.executeScript("window.scrollTo(" + eleX + "," + eleY + ")");
//get element focus and enable click, some cases can skip it
element.sendKeys("");

element.click();

Move to the corresponding place and click

Another cause anchor link like “” can’t be clicked in FFv63

So the solution code is below

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].innerHTML=arguments[1]", element, "sometext"); //change to text, so can click
element.click();

replace anchor inner html text, then we can get clickable.

 

3. Can not scroll to the view issue
Generally it is happened on long options with select tag…,when click select control, options item need to manually scroll to the item which want to click, but directly use element click function can’t trigger this operations, so below code solution is:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,+/- offset)", ""); // +/-:means scroll down or up to the page
new Actions(driver).moveToElement(element).perform();  //use Actions to scroll to element
element.click();

If select position is not good, we need to adjust first using above position solution.

 

4.Checkbox can’t be checked issue
Here we need to use js to fix:

js.executeScript("document.getElementById('" + element.getAttribute("id")+ "').setAttribute('checked','checked');");

These solution code can be considered locate catch block to avoid other cases conflict.
Also most issues we have to debug or manually trace the page source.

Leave a Reply

Your email address will not be published. Required fields are marked *