0

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.

  • 6
    Likely there are solutions: Your code is doing something wrong :-) but we cannot tell you until we see the offending code – Peter M. - stands for Monica Mar 29 '18 at 14:02
  • 2
    This is an interesting question, but as @PeterMasiar stated, we need more details. Are you zooming the page through your script? What method are you using to locate and click the element? What message are you getting? Please elaborate in greater detail. – Bill Hileman Mar 29 '18 at 14:26
  • Bill and Peter, Thank you for your reply. Please see my code above. I do not get any error message. It just only clicks on the wrong element. – sofina Mar 31 '18 at 23:09
1

As an alternative to .click() try clicking using JavaScript:

WebElement element = driver.findElement(By.id(id_name));
(JavascriptExecutor)driver.executeScript("arguments[0].click();", element);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.