2

My code below is basically selecting the dropdown controls on the form. It works in debug mode but fails to select the dropdown values in run mode. Dont know why this is happening. The browser i am using chrome

new SelectElement(driver.FindElement(By.Id("ctl00_ctl00_Contents_Contents_dropdownlistday"))).SelectByText("9");
                driver.FindElement(By.CssSelector("option[value=\"9\"]")).Click();
                new SelectElement(driver.FindElement(By.Id("ctl00_ctl00_Contents_Contents_dropdownlistmonth"))).SelectByText("May");
                driver.FindElement(By.CssSelector("option[value=\"May\"]")).Click();
                new SelectElement(driver.FindElement(By.Id("ctl00_ctl00_Contents_Contents_dropdownlistyear"))).SelectByText("2000");
                driver.FindElement(By.CssSelector("option[value=\"2000\"]")).Click();
Tom
  • 8,175
  • 41
  • 136
  • 267
  • try using some wait...in debug mode u anyhow wait to move forward...so time might be a issue.. – Vivek Singh Mar 20 '15 at 10:40
  • i tried putting wait and that isnt the issue. I have this same piece of code which works fine for another page – Tom Mar 20 '15 at 10:51
  • Another point to note is works fine in firefox – Tom Mar 20 '15 at 10:54
  • Is the main control list ID the same between debug and run mode? Is it possible that in run mode you are using a different version of ASP.NET that removes the ct100_ prefix? ( see http://stackoverflow.com/questions/4437717/asp-net-2-5-prefixing-ctl00-and-asp-net-4-not-prefixing-ctl00 for more info on the ct100_prefix) – Paul Mar 20 '15 at 11:03
  • At runtime, the id generated is ctl00_ctl00_Contents_Contents_dropdownlistday. – Tom Mar 20 '15 at 11:11
  • is it got to do with setting focus on the control – Tom Mar 20 '15 at 11:12
  • can u provide the stacktrace on chrome run? – Vivek Singh Mar 20 '15 at 12:13

3 Answers3

0

After selecting the option from dropdown, no need to click on that option again.

try with below code.

new SelectElement(driver.FindElement(By.Id("ctl00_ctl00_Contents_Contents_dropdownlistday"))).SelectByText("9");
new SelectElement(driver.FindElement(By.Id("ctl00_ctl00_Contents_Contents_dropdownlistmonth"))).SelectByText("May");
new SelectElement(driver.FindElement(By.Id("ctl00_ctl00_Contents_Contents_dropdownlistyear"))).SelectByText("2000");
Santoshsarma
  • 5,627
  • 1
  • 24
  • 39
  • i removed the click no difference. Though it works on debug mode. – Tom Mar 20 '15 at 11:57
  • Finding it quite strange. It works in debug mode as well firefox run mode. Only fails in chrrome run mode – Tom Mar 20 '15 at 11:58
0

Add this code to your appium project before finding the element.It works for me

try {
    Thread.sleep(10000);
} catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
}

Eg:

try {
    Thread.sleep(10000);
} catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
}
((AndroidDriver)   driver).swipe(startx1,starty1,endx1,starty1,2000);
P.S.
  • 15,970
  • 14
  • 62
  • 86
Rohan
  • 841
  • 1
  • 11
  • 22
0

It might be a very ordinary solution but try reloading the page before your action. It worked in a project of mine.

Deepak
  • 31
  • 2