我正在尝试使用Selenium来点击一个:: after伪元素.我意识到这不能通过WebDriver直接完成,但似乎无法通过Javascript找到一种方法.
这是DOM的样子:
<em class="x-btn-split" unselectable="on" id="ext-gen161">
<button type="button" id="ext-gen33" class=" x-btn-text">
<div class="mruIcon"></div>
<span>Accounts</span>
</button>
::after
</em>
Run Code Online (Sandbox Code Playgroud)
这就是上面的元素.对象的左侧是"按钮"元素,而后面元素是右侧,带有箭头,单击时会显示下拉菜单.正如您所看到的那样,右侧没有任何标识符,这部分是使得这很难做到的.
我已经在stackoverflow中看到了这两个链接,并试图将答案组合起来形成我的解决方案,但无济于事.
使用JavaScript在Selenium WebDriver中单击元素使用JavaScript在Selenium WebDriver中
查找伪元素
这是我的尝试之一:
string script = "return window.getComputedStyle(document.querySelector('#ext-gen33'),':before')";
IJavaScriptExecutor js = (IJavaScriptExecutor) Session.Driver;
js.ExecuteScript("arguments[0].click(); ", script);
Run Code Online (Sandbox Code Playgroud)
我得到这个错误:
System.InvalidOperationException: 'unknown error: arguments[0].click is not a function
(Session info: chrome=59.0.3071.115)
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)'
Run Code Online (Sandbox Code Playgroud)
我也尝试使用Selenium中的Actions类来引用鼠标左侧,类似于这个答案.我想这可能是因为我不知道测量的偏移是什么,文档似乎没有给出任何指示.我认为它是以像素为单位?
Actions build = new Actions(Session.Driver);
build.MoveToElement(FindElement(By.Id("ext-gen33"))).MoveByOffset(235, 15).Click().Build().Perform();
Run Code Online (Sandbox Code Playgroud)
这个尝试似乎点击某处,因为它没有给出错误,但我不确定在哪里.
我试图在c#中自动化Salesforce(Service Cloud),如果这有帮助的话.
也许有人可以提供解决方案?
我有两个具有相同属性的元素,但在页面上一次显示一个(当显示一个时,另一个消失).两者之间的唯一区别是显示的元素将具有':: before'选择.是否可以使用xpath或css选择器根据其id以及是否具有:: before来检索元素

假设我通过XPath找到了一个元素:
WebElement we = driver.findElement(By.xpath("some XPath"));
我知道我可以获得特定CSS属性we.getCssValue("some property")的值,但是我可以获得所有属性的值而不必明确提及它们的名称吗?
我试图通过以下方式获取CSS属性"content"的值:
WebElement plusOrMinusSign = currentEntityTypeLevel1.findElement(
By.xpath("i[@class='tree-branch-head']::after"));
System.out.println(plusOrMinusSign.getCssValue("content"));
Run Code Online (Sandbox Code Playgroud)
但是,我收到一个错误: The string 'i[@class='tree-branch-head']::after' is not a valid XPath expression.
似乎" ::after"不被承认.
HTML:
<i class="tree-branch-head" ng-class="iBranchClass()" ng-click="selectNodeHead(node)">::after
</i>
Run Code Online (Sandbox Code Playgroud)
CSS:
i:after {
content: "-";
}
Run Code Online (Sandbox Code Playgroud)
知道如何获得"内容"的价值吗?