java - Referencing unnamed element with Selenium WebDriver -
i'm new selenium, , i'm having trouble finding particular elements on webpage webdriver (in java). particular elements trying reference links, not have id/ other xml attributes associated them. not have access html source code, cannot add identifiers elements. i'm not can , can't done using findby functions, can take @ html , tell me how might find specified element (with end goal being use webelement.click() method on it).
<div class="col-md-12"> <h3>my registered cards</h3> <div id="cards" class="row list-group"> <div>
this line
<a href="/website/carddetails?cardnumber=1">
this line
<div class="tile col-md-3 img-rounded"> <div class="tile-inner"> <img class="group list-group-image col-md-12 hidden-xs hidden-sm" src="http://placehold.it/200x100/000/fff" alt=""> <div> <div class="row"> <h4 class="group inner list-group-tile-heading col-xs-12 col-md-12">card name</h4> </div> </div> </div> </div> </a> </div> <div>
this line
<a href="/website/carddetails?cardnumber=2">
this line
<div class="tile col-md-3 img-rounded"> <div class="tile-inner"> <img class="group list-group-image col-md-12 hidden-xs hidden-sm" src="http://placehold.it/200x100/000/fff" alt=""> <div> <div class="row"> <h4 class="group inner list-group-tile-heading col-xs-12 col-md-12">card name</h4> </div> </div> </div> </div> </a> </div> </div> </div>
i tried couple different ways, webdriver did not find correct element in both scenarios.
@findby(linktext = "card name") public list<webelement> cards;
and
@findby(xpath = "//div[@id='cards']/div/@a") public list<webelement> cards;
edit: siking not answer looking for, did point me in right direction.
what ended doing
@findby(xpath = "//div[@id='cards']/div/a") public list<webelement> cards;
if unclear, trying list of cards (specifically, card links) on website click in sequence
the selector
@findby(linktext = "card name")
is going find nothing, because looks text enclosed in a
tag.
the selector
@findby(xpath = "//div[@id='cards']/div/@a")
is looking attribute a
of element div
, under element div
has attribute id='cards'
... not want either.
you want:
@findby(xpath = "//div[@id='cards']//a")
which find first a
element under div
attribute id='cards'
.
hey, if else fails, try documentation. :)
Comments
Post a Comment