When I set my browsers’ zoom level to less than 100%, the chrome driver clicks on the wrong element. If I set it to 100%, I have no issue.
Are there any solutions to this problem?
*****************************
//This is my script to change the zoom level of my window browser. I am changing my browser zoom level from 100% to 75%
public void zoomOut()
{
for(int i=0; i<3; i++)
{
Robot robot;
try
{
robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_MINUS);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_MINUS);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
//I am using xpath to locate my element
@FindBy(xpath="//*/res-singleselect-lite[2]/div/label[@title='Road condition']/parent::*/div/div[3]/a/span[2]/b")
WebElement roadCondition;
@FindBy(xpath="//*/res-singleselect-lite[3]/div/label[@title='Wind Direction']/parent::*/div/div[3]/a/span[2]/b")
WebElement windDirection;
// ********I am calling this method first********************
public void selectRoadCondition(String roadConditionItemNo)
{
if (roadConditionItemNo != null && roadConditionItemNo != "")
{
objcommonResources.searchByItemNo(this.roadCondition,
Integer.parseInt(roadConditionItemNo),"Road Condition");
}
}
//******Then, I am calling this method to click on the element (dropdown box)*******
public String searchByItemNo(WebElement elementDropdownList, int itemNo, String fieldName)
{
if (itemNo>0)
{
elementDropdownList.click(); <= This code will click on the dropdown box
}
}
Note:
I am using Chrome browser. I want to click on the roadCondition element. But, the selenium clicks on the windDirection element. If I do NOT change my window browser's zoom level from 100% to any, selenium webdiver clicks on the roadCondition element.
If I use Firefox browser instead of Chrome browser, then it works fine even though I change my zoom level from 100% to any.