Zvika Nadav Zvika Nadav - 3 months ago 13
HTML Question

Clicking span button by id of the parent(with id) - selenium with java

Is it possible to click a

span
button which is under the
div
element, also I would like to use the id of the input to make my test stable.

HTML:

<div class="idit-go">
<input id="IDITForm@checkRuleVO" class="GoLong align-left idit-go-text" type="text" value="" title="Validation Rule" tabindex="257" name="unknown" ignoredisableenableaction="true" helptextinfo="" disabled="">
<div class="idit-go-buttons">
<span id="IDITForm@checkRuleVOGoClearButtonClear" class="idit-go-clear" title="Clear" tabindex="259" onclick="clearField('IDITForm@checkRuleVOhidden');clearField('IDITForm@checkRuleVO');;">
<span class="fa-stack idit-go-button" value="" title="" tabindex="258" onclick="newPerformSubAction('selectRule',true);">
<i class="fa fa-stack-1x fa-square"></i>
<i class="fa fa-stack-1x fa-ellipsis-h"></i>
</span>
</div>


How it looks on screen:

demo

As you can see the 3 dots button to the right, that is the button I'd like to click. Thanks in advance.

Answer

In this case you could identify the span that has the id attribute and then just use following-sibling (from your example they seems to be on the same level).

driver.findElement(By.xpath(".//[@id='IDITForm@checkRuleVOGoClearButtonClear']/following-sibling::span"));
Comments