为了获得伪元素,这些行有什么区别
what is the difference in these lines in order to get the pseudo element
这两个获取伪元素的选项有什么区别,或者获取这些元素的方法是什么,因为一行包含 document.queryselector 而另一行持有一个元素数组
JavascriptExecutor js = (JavascriptExecutor)driver;
String script = "return window.getComputedStyle(document.querySelector('#validationError'),':before').getPropertyValue('content')";
String content = (String) js.executeScript(script);
和
JavascriptExecutor js = (JavascriptExecutor) driver;
String iconUrl = (String) js.executeScript("return window.getComputedStyle(arguments[0],':before').getPropertyValue('content');", icon);
在第一条语句中,您直接在 Web 元素上执行 Javascript 以获取它的 :before
值。在第二个语句中,您使用 WebDriver 查找 Web 元素,然后将该元素作为参数传递给 JavaScript,以在其上执行脚本。
如果 icon
和 #validationError
return 是相同的元素,则脚本在功能上是相同的。第一个用JS找元素,第二个用Selenium找元素,后面用一个参数。
这两个获取伪元素的选项有什么区别,或者获取这些元素的方法是什么,因为一行包含 document.queryselector 而另一行持有一个元素数组
JavascriptExecutor js = (JavascriptExecutor)driver;
String script = "return window.getComputedStyle(document.querySelector('#validationError'),':before').getPropertyValue('content')";
String content = (String) js.executeScript(script);
和
JavascriptExecutor js = (JavascriptExecutor) driver;
String iconUrl = (String) js.executeScript("return window.getComputedStyle(arguments[0],':before').getPropertyValue('content');", icon);
在第一条语句中,您直接在 Web 元素上执行 Javascript 以获取它的 :before
值。在第二个语句中,您使用 WebDriver 查找 Web 元素,然后将该元素作为参数传递给 JavaScript,以在其上执行脚本。
如果 icon
和 #validationError
return 是相同的元素,则脚本在功能上是相同的。第一个用JS找元素,第二个用Selenium找元素,后面用一个参数。