4

In my application, there is a drop down to select "Estimation Date":

enter image description here

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();  
    }
}
  • 1
    Hi 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! – NarendraC Jun 27 '17 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 Jun 28 '17 at 4:00
  • Great. Its fine, I have not used JS. You can use. I will add my answer below now, accept! – NarendraC Jun 28 '17 at 4:23
2

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?
2

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 Jun 28 '17 at 3:55
  • @Aalok okay, thanks, what if you do est_date.selectByVisibleText("Since ");? (see the space after the "Since"). – alecxe Jun 28 '17 at 4:00
  • Okay. Will try that and share an update because I didn't put a space earlier. – Aalok Jun 28 '17 at 4:02
  • Tried that but no success. Seems like Selenium does not get along well with angular. :). Thanks though! – Aalok Jun 28 '17 at 7:22
1

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: Since – Aalok Jun 27 '17 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 Jun 27 '17 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 Jun 27 '17 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.