selenium - Webdriver - Locate Input via Label (Python) -
how locate input field via label using webdriver?
i test web form unfortunately uses dynamically generated ids, they're unsuitable identifiers.
yet, labels associated each web element strike me suitable. unfortunately not able few suggestions offered on web. there 1 thread here @ so, did not yield accepted answer:
selenium webdriver java - clicking on element label not working on labels
to solve problem in java, commonly suggested locate label anchor via text content , specifying xpath input element:
//label[contains(text(), 'text_to_find')]
i not sure how in python though. web element:
<div class="inputtext"> <label for="input"> <span> label text </span> <span id="idd" class="required" title="required"> * </span> </label> <span class="text"> <input id="input" class="text colouredfocus" type="text" onchange="var wcall=wicketajaxpost(';jsessionid= ... ;" maxlength="30" name="z1013400259" value=""></input> </span> <div class="requiredlabel"> … </div> <span> … </span> </div>
unfortunately not able utilize css or xpath expressions on site. ids , names changed.
the solution problem found dirty 1 - parsing source code of page , extract ids string operations. not way webdriver intended used, works robustly.
code:
lines = [] line in driver.page_source.splitlines(): lines.append(line) if 'label text 1' in line: id_l1 = lines[-2].split('"', 2)[1]
python selenium xpath selenium-webdriver webdriver
No comments:
Post a Comment