【发布时间】:2021-04-17 09:21:38
【问题描述】:
我试图找到一个“按钮”并单击它,但它没有 id。 我尝试使用 Xpath 甚至 cssSelector 但没有任何效果。
这是按钮的元素:
div style="cursor: grabbing;" title="Approved Forms" onclick="goToForms(0)" class="col-lg-2 col-sm-6"
我试过这个:
driver.findElement(By.xpath("//div[contains(@title=,'Approved Forms')]")).click();
driver.findElement(By.xpath("/html/body/div[3]/div/div/div[2]/div[1]")).click(); *copy xpath*
driver.findElement(By.cssSelector(['title="Approved Forms"'])).click(); *has a sintax errors, not sure how to write it*
【问题讨论】:
-
您需要先验证 XPath 和 CSS,然后再将它们包含到您的测试脚本中。您可以使用 chrome 开发人员工具来验证 CSS 和 XPath。 [阅读有关 XPath 的更多信息](pragmatictestlabs.com/2020/01/28/…)。 Free course on Location strategies
标签: java selenium selenium-webdriver selenium-chromedriver selenium-ide