0

I want to access the following elements with the only indicator of value using java. All the text values identified with option value, under name="txnSource", are selections that can be made from a drop-down selector.

I'd like to automate the selection of the value from the drop-down box is why I need to know how to access the values... There is no "findElement(By.value("value"))" so how can I access the element by value ??

I think accessing by xpath would be extremely volatile. Also, any change in the options in the drop-down would require a whole reworking of the xpath identification.

enter image description here

3 Answers 3

3

In Java, you can do any of those:

driver.findElement(By.cssSelector("option[value='500']")).click();

or

driver.findElement(By.xpath("//option[@value='500']")).click();

or use Select and selectByValue()

Select select = new Select(driver.findElement(By.name("txnSource")));
select.selectByValue("500");
Sign up to request clarification or add additional context in comments.

Comments

2

In Java I think it would be something this way

IWebElement dropDownListBox = driver.findElement(By.Name("txnSource"));
SelectElement clickThis = new SelectElement(dropDownListBox);
clickThis.SelectByValue("500");

This is how it is done in Ruby

Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "txnSource")).select_by(:value, "500")

Comments

1

You can select an option from pick list like this

new Select(driver.findElement(By.name("txnSource"))).selectByVisibleText("Text- Stock Movement (DOGS)");

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/Select.html

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.