In my application, there is a drop down to select "Estimation Date":
Please find below my test case. It is failing at the line where I am trying to select "Since":
public class dropdown_issue {
GenericFunctions gf= new GenericFunctions();
@Test(enabled = true)
public void dropdown () throws InterruptedException{
System.setProperty("webdriver.gecko.driver","D:\\Selenium\\BrowserDrivers\\geckodriver.exe");
WebDriver dr=new FirefoxDriver();
dr.get("http://10.127.129.79:8080/abc");
Thread.sleep(3000);
dr.findElement(By.id("username")).sendKeys("user");
dr.findElement(By.id("password")).sendKeys("user");
dr.findElement(By.xpath("//button[@type='submit']")).click();
WebElement est_date_dd= dr.findElement(By.xpath("//div[@class='clearfix']//select[@name='est-date']"));
Select est_date= new Select(est_date_dd);
est_date.selectByValue("Since");
Thread.sleep(3000);
dr.quit();
}
}
-
1Hi Aalok, I observe this same behavior. "SelectByValue( )" is not working sometime. Work Around, When you open listbox using name I was able to click & set the actual value to list box. Let me know if it works for you too!Narendra Chandratre– Narendra Chandratre2017年06月27日 07:13:16 +00:00Commented Jun 27, 2017 at 7:13
-
Thanks @NarendraC, the workaround worked. Now, trying to do it the right way. Is there any chance that I use Java script in order to accomplish this?Aalok– Aalok2017年06月28日 04:00:06 +00:00Commented Jun 28, 2017 at 4:00
-
Great. Its fine, I have not used JS. You can use. I will add my answer below now, accept!Narendra Chandratre– Narendra Chandratre2017年06月28日 04:23:41 +00:00Commented Jun 28, 2017 at 4:23
3 Answers 3
I observe this same behavior. "SelectByValue( )"
doen not working sometime. Below solution worked well for me :
- Click on listbox
- Once list & options are visible, Assert/Check visibility for option which you want to select preferably by name locator
- Then using
click()
perform click on that option & it will set the actual value to list box. - For confirmation, again you can check correct value is selected in listbox or not?
The value of the option
is actually string:SINCE
.
Either use this value or select by visible text:
est_date.selectByValue("string:SINCE");
// or est_date.selectByVisibleText("Since ");
-
Hello @alecxe, I figured it out and updated the value. But that didn't work either. But, thanks for analyzing the code. 1 up for that.Aalok– Aalok2017年06月28日 03:55:15 +00:00Commented Jun 28, 2017 at 3:55
-
@Aalok okay, thanks, what if you do
est_date.selectByVisibleText("Since ");
? (see the space after the "Since").alecxe– alecxe2017年06月28日 04:00:00 +00:00Commented Jun 28, 2017 at 4:00 -
Okay. Will try that and share an update because I didn't put a space earlier.Aalok– Aalok2017年06月28日 04:02:15 +00:00Commented Jun 28, 2017 at 4:02
-
Tried that but no success. Seems like Selenium does not get along well with angular. :). Thanks though!Aalok– Aalok2017年06月28日 07:22:50 +00:00Commented Jun 28, 2017 at 7:22
Looks like you are trying to automate AngularJS website..
From locators perspective, I don't see any problem in the code..
I would suggest to do the following -
Before selecting the drop down, try clicking on dropdown and see the code works or not.
WebElement est_date_dd=
dr.findElement(By.xpath("//div[@class='clearfix']//select[@name='est-date']"));
est_date_dd.click();
Select est_date= new Select(est_date_dd);
est_date.selectByValue("Since");
Let me know if this doesn't work.
Thanks!
-
Thanks for your inputs. I am getting this error when trying to select value "Since": FAILED: dropdown org.openqa.selenium.NoSuchElementException: Cannot locate option with value: SinceAalok– Aalok2017年06月27日 07:16:56 +00:00Commented Jun 27, 2017 at 7:16
-
Can you please try selecting with index and see whether it works or not? Are you providing the exact text which is there in Element tree?mashkurm– mashkurm2017年06月27日 08:44:40 +00:00Commented Jun 27, 2017 at 8:44
-
Yes. I am proving the same exact text but it didn't work. I tried with the index too. But doesn't seem like working. :(. Although, thank you for you efforts.Aalok– Aalok2017年06月27日 08:48:22 +00:00Commented Jun 27, 2017 at 8:48
Explore related questions
See similar questions with these tags.