java - I am not able to select the dropdown using selenium webdriver please -


i trying select drop down of site , proceed buy show, not able please help.

 system.setproperty("webdriver.chrome.driver", "c:/selenium/chromedriver.exe");  webdriver driver = new chromedriver();                driver.get("http://www.theatrepeople.com/");   driver.findelement(by.id("edit-show")).click();   new select(driver.findelement(by.id("edit-show"))).selectbyvisibletext("the 39 steps");  driver.findelement(by.id("edit-date-datepicker-popup-0")).click();  driver.findelement(by.linktext("27")).click();  driver.findelement(by.id("edit-ticket-no")).click();  new select(driver.findelement(by.id("edit-ticket-no"))).selectbyvisibletext("1 ticket");  driver.findelement(by.id("edit-submit-1")).click(); 

use following code. uses java script select text based upon it's valued. nice question. got learn.

static webdriver driver;      public static void main(string[] args)      {         system.setproperty("webdriver.chrome.driver", "d:\\tocustomer_31_5_13\\src\\main\\resources\\drivers\\chromedriver.exe");           driver = new firefoxdriver();                         driver.get("http://www.theatrepeople.com/");            driver.findelement(by.id("edit-show")).click();           webelement show = driver.findelement(by.xpath("//div[@id = 'edit-show-wrapper']//div[@id = 'shownamewrap']"));           list<webelement> l = show.findelements(by.tagname("option"));           string valuetoselect = getattibutevalueforshow(l, "the american plan");                     driver.findelement(by.id("mini-basket-ajax")).click();           selectvalueindropdown(valuetoselect);            }       public static string getattibutevalueforshow(list<webelement> li, string showname)     {         int j =0;         string value = null;          for(int =0; i<li.size(); i++)          {              j = j +1;              string dropdowntext = li.get(i).gettext();              if(dropdowntext.equalsignorecase(showname))              {                 value =  driver.findelement(by.xpath("//div[@id = 'edit-show-wrapper']//div[@id = 'shownamewrap']//option[" + j +"]")).getattribute("value");                 system.out.println(value);                  break;              }          }          return value;     }      public static void selectvalueindropdown(string value)     {         javascriptexecutor js = (javascriptexecutor) driver;          string jscmd = "document.getelementsbyname('show')[0].value='" + value + "'";          js.executescript(jscmd);     } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -