html - double slash for xpath. Selenim Java Webdriver -
i using selenium webdriver. have doubt xpath.
if have following code example:
<div> <div> <div> <a> <div> </div> </a> </div> </div> </div> and want locate element in last <div>. think have 2 options xpath.
first option single slash:
driver.findelement(by.xpath("/div/div/div/a/div")).click(); second option using double slash (and here have doubt).
driver.findelement(by.xpath("//a/div")).click(); is going search in <a> directly, happens if html example code part of bigger code , in bigger code more "<a>"?. method exactly?
what happens example if this:
driver.findelement(by.xpath("//div")).click(); would looks if every <div> found in html code?
thanks lot
first of all, avoiding // right thing - so, first expression show perfect.
would looks if every
<div>found in html code?
yes, exactly. xpath expression like
//div will select all div elements in document, regardless of are.
what happens if html example code part of bigger code , in bigger code more
<a>?. method exactly?
then, let make html "bigger":
<div> <a> <p>c</p> </a> <div> <div> <a> <div>a</div> </a> </div> <a> <div>b</div> </a> </div> </div> as can see, have added 2 more a elements - 1 of them contains div element. assuming new document input, there difference between
/div/div/div/a/div which select only <div>a</div> result, and
//a/div which select both <div>a</div> , <div>b</div> - because exact position of a in tree irrelevant. none of them select first a element contains p.
Comments
Post a Comment