Simple Selenium RegEx Java -
i not familiar how use reg ex within selenium, hoping assistance this. currently, when run, doesn't locate elements not surprising.
list<webelement> elements = seleniumcommands.mydriver.findelements(by.id("assessment-answer-{[0-9]+}-1"));
the ids of i'm trying grab like
<input id="assessment-answer-5713185-1" ...>
here larger html parse of site selection-writing purposes.
<div id="assessment-page-1"> <ul id="question-row-5713185" class="plus-card card-white question-row"> <li id="question-collapsible-5713185" class="question-collapsible"> <li id="answers-container-5713185" class="answers-container"> <div class=" assessment-two-answers"> <input id="assessment-answer-5713185-1" type="radio" value="1" name="assessment-answer-5713185"/> <label class="assessment-answer-right answer-1" for="assessment-answer-5713185-1">agree</label> <input id="assessment-answer-5713185-2" type="radio" value="2" name="assessment-answer-5713185"/> <label class="assessment-answer-left answer-2" for="assessment-answer-5713185-2">disagree</label> </div> </li> </ul> <ul id="question-row-16432246" class="plus-card card-white question-row"> <li id="question-collapsible-16432246" class="question-collapsible"> <li id="answers-container-16432246" class="answers-container"> </ul> <ul id="question-row-62590768" class="plus-card card-white question-row"> <ul id="question-row-16162378" class="plus-card card-white question-row"> <ul id="question-row-34160582" class="plus-card card-white question-row"> ... </div>
i not experienced reg ex know cause of problem, apologize simple question, appreciate help.
use starts-with , ends-with locator/notation:
list<webelement> elements = seleniumcommands.mydriver.findelements(by.cssselector("[id^=assessment-answer-][id$=\"-1\"]"));
you may need wait element become visible:
webdriverwait wait = new webdriverwait(seleniumcommands.mydriver, 5); wait.until(expectedconditions.visibilityofelementlocated(by.cssselector("[id^=assessment-answer-][id$=\"-1\"]"))); list<webelement> elements = seleniumcommands.mydriver.findelements(by.cssselector("[id^=assessment-answer-][id$=\"-1\"]"));
Comments
Post a Comment