manu T
manu T

Reputation: 11

Not able to find correct Xpath

Xpath not identifying while running script in Selenium robot Framework

<div class="divRptData">
    <hr class="hrConnector" />
    <span style="float: left; cursor: pointer" class="tree-box tree-box-expand" onclick="javascript: toggleBranch(this, 'level2_ABC')"/>
    <span style="margin-left: 4px" class="ng-binding">text</span>
</div>

I already tried below XPATH for above code, which is working when I find it manually, but while running script it is not identifying.

//span[@onclick="javascript: toggleBranch(this, 'level2_ABC')"]

//div[3]/div/div/div/div[4]/div[1]/span[1]

Can some help me out how to handle this.

Upvotes: 1

Views: 92

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193088

You can use either of the following _Xpath_s:

"//div[@class='divRptData']/hr[@class='hrConnector']//following::span[1]"

Or

"//div[@class='divRptData']//span[@class='tree-box tree-box-expand' and contains(@onclick, 'level2_ABC')]"

Upvotes: 0

Ardesco
Ardesco

Reputation: 7441

I suspect you are suffering from quote marks problems. Try:

//span[@onclick=\"javascript: toggleBranch(this, 'level2_ABC')\"]

You can check this XPath in your browser by typing the following in the console:

$x("//span[@onclick=\"javascript: toggleBranch(this, 'level2_ABC')\"]")

(The above works on Chrome, I think all browsers support the syntax now)

Upvotes: 4

Related Questions