java - 如何使用 Selenium 和 Java 通过类名识别元素并单击它?

标签 java selenium xpath css-selectors webdriverwait

enter image description here

通过类单击按钮,因为它没有 ID 。还是通过值(value)?

尝试过 className 、 cssSelector 、partialLinkText 和 LinkText 但遗憾的是单击“保存”按钮不起作用

System.out.println("Succesful in Saving Product ");
WebElement save = driver.findElement(By.className("bttn-positive save-button"));
save.click();

应该能够点击保存按钮

最佳答案

我们不能在className定位器中使用多个类名。因此,您可以使用具有多个类名称的 XPath 定位器,如下所示 (//input[@class='bttn-positive save-button'])

代码:

System.out.println("Succesful in Saving Product ");
WebElement save = driver.findElement(By.xpath("//input[@class='bttn-positive save-button']"));
save.click();

关于java - 如何使用 Selenium 和 Java 通过类名识别元素并单击它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57488990/

相关文章:

java - 配置 id 序列 hibernate 生成器

java - 打印出0-100的奇数,不包括X、Y、Z

java - 可以使 java.util.ArrayList<T>.toArray() 更友好吗?

javascript - 是否有一个全局浏览器对象我可以添加一个监听器来捕获所有抛出的错误?

java - Sonar : Create new rule for Android Lint

java - Eclipse - 什么是派生文件警告

Python 无法使用 Selenium 识别表格单元格中的文本

python - 将 Selenium 与 Python 结合使用 : Error when using select boxes on IE9

javascript - 如何在 JavaScript 中从 Selenium 中具有特定类的标签获取内容

python - 如何在Python中从xml文档中获取特定标签