有没有办法点击CSS中定义但不属于html标签的背景图像?我需要单击具有 @class=hitLocation 的 div 标签。
<ul id="uxFolderTree_uxFolderTree_template_TreeRootElement" class="ui-tree-root">
<li class="-ui-tree-branch -ui-tree-folder -ui-tree-type-root collapsible" data--selectionmode="None" data-level="0" data-path="0" data-rootid="0" data-parentid="0" data-id="0">
<div class="hitLocation">
CSS 是
.ui-tree .ui-tree-branch.collapsible > .hitLocation {
background-image: url("/WorkArea/FrameworkUI/images/icons/plus.png");
background-position: 0 center;
cursor: pointer;
最佳答案
不直接,不。
您可以:
只需单击
hitLocation
元素即可。 WebDriver 隐式单击元素的中心,因此可能已经足够了。使用高级交互 API 并指定要单击元素中的哪个位置。
例如,单击从
hitLocation
元素左上角开始计算的位置[1,1]
。WebElement hitLocation = driver.findElement(By.className("hitLocation")); new Actions(driver) .moveToElement(hitLocation, 1, 1) .click() .perform();
关于selenium-webdriver - 从 css 单击背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18601413/