简体   繁体   中英

Selenium Element Click not Working after Zoom In while using Chrome

Need help in automating my use case using selenium

My Usecase to automate

  1. Navigate to a page
  2. Zoom Out page ( I am aware of the fact 100% is accurate for selenium scripts, but I have to make the page to 90% )
  3. Click on Save button in the page
  4. Reset zoom level of the page

I tried the following two approaches

Approach#1 : ( With this there is no change in zoom setting and script failed )

mysavelement.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
mysavelement.click();
mysavelement.sendKeys(Keys.chord(Keys.CONTROL, "0"));

Approach#2 : ( With this approach zoom setting got changed and script passed. Though script passed, click functionality is not working means save not happening )

 Robot robot = new Robot();
 robot.keyPress(KeyEvent.VK_CONTROL);
 robot.keyPress(KeyEvent.VK_SUBTRACT);
 mysavelement.click();

I too have experienced click functionality sometimes failing on chrome browser when I try to zoom-in/out the browser. But, for firefox, it works fine. I don't know the reason for such a behavior, but javascript click workaround helped in such scenarios. Try, below work-around if not already tried:

(JavascriptExecutor)driver.executeScript("arguments[0].click();", mysavelement);

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