admin管理员组文章数量:1317733
I'm new to test automation in Java with Selenium and the Cucumber plugin. I need to click on an object on a website without identifying xpath, but simply declaring its position on the horizontal and vertical axis of the screen. How can I do it?
How do I identify it by analyzing the page and what is the listing in Selenium with Cucumber?
I'm new to test automation in Java with Selenium and the Cucumber plugin. I need to click on an object on a website without identifying xpath, but simply declaring its position on the horizontal and vertical axis of the screen. How can I do it?
How do I identify it by analyzing the page and what is the listing in Selenium with Cucumber?
Share Improve this question edited Jan 29 at 9:05 Mark Rotteveel 109k229 gold badges156 silver badges220 bronze badges asked Jan 29 at 8:59 nowaySyncnowaySync 1152 silver badges13 bronze badges 2- 2 Clicking by X and Y is a very bad idea, because that is generally resolution and rendering engine dependent. If anything changes in the resolution or the rendering engine, your coordinates will be off. – Mark Rotteveel Commented Jan 29 at 9:06
- Why do you feel like you have to click on coordinates instead of using a locator? – JeffC Commented Jan 29 at 14:50
1 Answer
Reset to default 0If you need to click on a specific position on a webpage without using XPath, you can do it using Selenium’s Actions class in Java. Simply move to the desired x, y coordinates and perform a click. Here's a basic example.
Actions actions = new Actions(driver);
actions.moveByOffset(500, 300).click().perform();
If you are using Cucumber framework, you can use below code,
@Then("I click on coordinates {int} and {int}")
public void iClickOnCoordinates(int x, int y) {
Actions actions = new Actions(driver);
actions.moveByOffset(x, y).click().perform();
}
本文标签: javaHow to click on an element based on the x and y axisStack Overflow
版权声明:本文标题:java - How to click on an element based on the x and y axis? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742007957a2412343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论