xpath - Validating form data that uses a selector with Selenium -
i attempting automate checking values of form. figured out how check values submitted via send_keys, submitted via selector giving me trouble. i'm n00b when comes automation.
this works:
driver.find_element_by_xpath("//*[@name='currentaddress.lineone'][@value='123 lane']") this not:
driver.find_element_by_xpath("//*[@name='currentaddress.stateabbrev'][@value='tx']") the code governs currentaddress.stateabbrev
<select class="form-control" data-val="true" data-val-required="* state required" id="currentaddress_stateabbrev" name="currentaddress.stateabbrev"><option value=""></option> when try validate state, this:
selenium.common.exceptions.nosuchelementexception: message: no such element: unable locate element: {"method":"xpath","selector":"//*[@name='currentaddress.stateabbrev'][@value='tx']"} the form value stores input 'tx' page shows state 'texas'. i've tried looking either, still cannot locate element. attempting locate via either @name or @id doesn't change outcome.
i haven't tested code, should work.
//rather creating object of webelement create object of select select statedropdown = new select(driver.findelement(by.xpath("//select[@class='form-control']")); //to select visible text, pass text statedropdown.selectbyvisibletext(""); //get text of first selected option string selectedvalue = statedropdown.getfirstselectedoption().gettext();
Comments
Post a Comment