java - Selenium Webdriver cannot choose a value in a dropdown list -
i trying implement selenium webdriver
using java
. basically, have website blank field. once user click on field, drop-down list 5 options appear , user should choose 1 option.
the codes this
<!-- language: lang-html --> <div class="default-form w-border scheduleaddfrom" style="display: block;"> <div> <div class="section frameless nopadding nomargin" data-form-element="sectionheading" style="min-width: 100%;"> <div class="section-body frameless nopadding nomargin"> <div class="default-form"> <div class="form-row required-message hidden" style="min-height: 25px;"> <div class="form-row print-avoid-page-break" data-form-element="fieldedit" style="min-height: 25px;"> <label for="">department</label> <input id="schedule-00-row136153aa-9fa8-499b-8458-2b155443223be-taskid-display" class="ui-autocomplete-display validate widget" type="text" autocomplete="off"> <span class="ui-autocomplete-display-icon"></span> <div class="subhidden"> <select id="schedule-00-row136153aa-9fa8-499b-8458-2b155443223be-taskid" class="validate widget " data-default-value="" tabindex="5000" data-display-id="schedule-00-row136153aa-9fa8-499b-8458-2b155443223be-taskid-display"> <option value=""></option> <option value="opt1">option 1</option> <option value="opt2">option 2</option> <option value="opt3">option 3</option> <option value="opt4">option 4</option> <option value="opt5">option 5</option> </select>
i tried use java codes choose option 2
webdriverwait wait = new webdriverwait(driver, 100); wait.until(expectedconditions.visibilityofelementlocated(by.cssselector(".form-row.print-avoid-page-break>label"))); //start find element. id dynamically randomly generated system each time page loads except last part taskid, looking string taskid select dropdown = new select (driver.findelement(by.xpath(".//*[contains(@id,'taskid')]"))); dropdown.selectbyvalue("opt2");
selenium
returns error
org.openqa.selenium.elementnotvisibleexception: element not visible: element not visible , may not manipulated
i have feeling caused <div class="subhidden">
, not sure. suggestion highly appreciated. thanks.
tested code block below , looks fine. looking @ html
it's fair assumption selector not uniquely return intendet element. believe want select
tag containing id
taskid
. tag dependent search possibly //select[contains(@id,'taskid')]
since <input id="schedule-00-row136153aa-9fa8-499b-8458-2b155443223be-taskid-display"
has id same text taskid
and going forward suggest test xpath
before plug test, @ least saying experience.
webdriverwait wait = new webdriverwait(driver, 100); selectelementselector = by.xpath("//select[contains(@id,'taskid')]"); webelement selectelement = wait.until(expectedconditions.presenceofelementlocated(selectelementselector)); select dropdown = new select (selectelement); dropdown.selectbyvalue("opt2");
edit
another possible option can finding element along options proper selector. again, must test selector make sure it's unique , want.
webdriverwait wait = new webdriverwait(driver, 100); string optiontoselect = "opt1"; //selector trick here selectelementselector = by.cssselector("select[id*='taskid']>option[value='" + optiontoselect + "']"); wait.until(expectedconditions.presenceofelementlocated(selectelementselector)).click();
Comments
Post a Comment