Unable to click on list button option in selenium : Exception Element not visible -
hi trying select on list option cold , flu getting element not visible exception, can please me how select in selenium script.
site url : http://www.healthdirect.gov.au/symptom-checker/tool?symptom=cold
colds , flu
here selenium code
public void selectspecificsymptom(string arg) throws interruptedexception { // todo auto-generated method stub switch(arg.tolowercase()) { case "cold , flu": /* actions actions = new actions(driver); webelement menuhoverlink = driver.findelement(by.xpath("//*[@ng-true-value='49|feeling sick or unwell|1']")); actions.movetoelement(menuhoverlink); actions.click(); actions.perform();*/ thread.sleep(5000); driver.findelement(by.xpath("//*[@ng-true-value='49|feeling sick or unwell|1']")).click(); driver.findelement(by.id("submitanswer")); break; default: system.out.println("not valid option"); break; } }
try code:
public class stack{ @test public static void select() throws interruptedexception{ webdriver driver = new firefoxdriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlywait(50, timeunit.seconds); driver.get("http://www.healthdirect.gov.au/symptom-checker/tool"); //wait iframe , switch webdriverwait wait = new webdriverwait(driver, 30); webelement frame = wait.until(expectedconditions.visibilityofelementlocated(by.xpath("//*[contains(@id, 'easyxdm_default')]"))); driver.switchto().frame(frame); thread.sleep(11000); //get health topics , select 1 matches list<webelement> l = driver.findelements(by.xpath("//*[@id='leftcol']/div/button")); (int = 0; < l.size(); i++) { system.out.println(l.get(i).gettext()); if (l.get(i).gettext().equalsignorecase("ear, nose , throat")){ l.get(i).click(); thread.sleep(2000); //get symptoms , select needed list<webelement> l1 = driver.findelements(by.xpath("//*[@id='contentheight']/div[2]/button")); //place second loop second list here l1.get(1).click(); //just test 'colds , flu' link } }
notes:
- you have have 1 iframe on there, need switch before want click on element
- i had bad internet when trying, adjust thread.sleeep() or wait element explicit waits
- do remember switch iframe if want operate outside
Comments
Post a Comment