1

how to select a value from dropdown using selenium java webdriver using xpath? depending on the option selected in the dropdown, fields appear .so that I need t enter values in it. My problem is I am not getting the fields after selecting the option in dropdown.After a long period of time it is appears, mean while error appears

2
  • do you have any code? Commented Jul 29, 2013 at 11:32
  • You need to use wait for element strategy until the field appears Commented Jul 30, 2013 at 10:00

4 Answers 4

1

You can click the drop down and wait for the options to get displayed and then you can click the option from it.

or

Select select = new Select(driver.findElement(By.id("drop_down_id")));

select.selectByIndex(`index_value_of_option`);
Sign up to request clarification or add additional context in comments.

Comments

1

Jyotsna... Your script need to wait till the field appear. For this you need to use any of the wait condition.

implicit wait

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

or sleep condition

Thread.sleep(2000);

or you can use Fluent wait (the best one as per my suggestion)

public WebElement fluentWait(final By locator) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);

    WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
        }
    });

    return  foo;
};

fluentWait function returns your found web element. From the documentation on fluentWait: An implementation of the Wait interface that may have its timeout and polling interval configured on the fly. Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page. Details you can get here

Usage of `fluentWait in your case be the following:

WebElement textbox = fluentWait(By.id("textbox"));

Comments

0

Sample statements to open browser, load URL and select value from dropdown

static WebDriver driver;
System.setProperty("webdriver.ie.driver","C:\\(Path)\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();

driver.get("EnterURLHere");          
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);

Select value1 = new Select(driver.findElement(By.id("LocateId")));    
value1.selectByVisibleText("ValueToBeSelected");    //Select Character from dropdown list

Comments

0

you can add wait so that the problem of late loading would be resolve.

driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);

or,

Thread.sleep(2000);

For selecting from drop down , there are multiple ways from which one can select :

Select dropdown = new Select(driver.findElement(By.id(""))); // By id
dropdown.selectByVisibleText(""); // By Visible text
dropdown.selectByIndex(1); // By index 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.