简体   繁体   English

Selenium测试因Java失败

[英]Selenium test fails with java

I use Selenium with cucumber in Java and when trying to do that : 我在Java中将Selenium与黄瓜配合使用,并且在尝试这样做时:

WebElement MyAccountLink = driver.findElement(By.className("btn-outlined-white_medium_block"));
MyAccountLink.click();

I got this error: 我收到此错误:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"class name","selector":"btn-outlined-white_medium_block"}

How can i solve it ? 我该如何解决? Thanks. 谢谢。

use 'XPath' or 'cssSelector' instead of 'className', because it doesn't matters which locator you are using. 使用“ XPath”或“ cssSelector”而不是“ className”,因为使用哪个定位器都没有关系。 you need to find the element and do automation on that element. 您需要找到该元素并对该元素进行自动化。

WebElement MyAccountLink = driver.findElement(By.xpath("right click on element and copy xpath and paste it here"));
MyAccountLink.click();

Hope XPath will work in any case. 希望XPath在任何情况下都能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM