Reputation: 45
Is there a way to click on the background image which is defined in the CSS but not part of the html tag? I need to click on the div tag that has @class=hitLocation.
<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">
the CSS is
.ui-tree .ui-tree-branch.collapsible > .hitLocation {
background-image: url("/WorkArea/FrameworkUI/images/icons/plus.png");
background-position: 0 center;
cursor: pointer;
Upvotes: 2
Views: 1769
Reputation: 38434
Not directly, no.
You can either:
simply click the hitLocation
element. WebDriver implicitly clicks into the center of the element, so it might be good enough.
Use Advanced Interactions API and specify at which location in the element you want to click.
For example, this clicks at position [1,1]
counting from the top-left corner of the hitLocation
element.
WebElement hitLocation = driver.findElement(By.className("hitLocation"));
new Actions(driver)
.moveToElement(hitLocation, 1, 1)
.click()
.perform();
Upvotes: 2