使用 Selenium Webdriver 与伪元素交互?

时间:2021-06-18 06:48:12

标签: selenium selenium-webdriver selenium-chromedriver

我正在使用带有 Java 的 Selenium Webdriver。 我试图与包含为伪元素 ::before

的锚标记进行交互

但我无法与锚元素进行交互。 这是 HTML 结构的屏幕截图。 enter image description here

JavaScriptExecutor,我了解,我们可以使用 window.getComputedStyle().getPropertyValue() 获取 propertyValue,但我不确定如何与 <a> 元素交互并执行 Click。

最初,我尝试单击锚元素,而没有将伪元素视为简单的元素交互。

获取元素: private By tabRawView_By_CSS = By.cssSelector("[tabid='raw-view'][role='tab']"); enter image description here

enter image description here

但是这块没有抛出任何错误,但它也没有点击元素。

然后我想到使用 JavaScriptExecutor 并尝试首先在开发人员工具中运行,如下图所示,但找不到合适的选项。 enter image description here

有人可以推荐吗?

1 个答案:

答案 0 :(得分:0)

如果是 Java 绑定,并且您想要做的就是在具有 click 的 achor 标记上 Raw view as a text

您可以尝试使用 ExplicitWaits

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Raw View"))).click();