0

I want to select an item from a drop down menu in selenium 2, in combination with phpunit. The class I use is PHPUnit_Extensions_Selenium2TestCase. I know in selenium 1 it's:

 $this->select("id=dt-general-input", "index=3");

But how des this convert to selenium 2? To select an element you do:

$this->select($this->byId("dt-general-input"));

But how do I select the 3rd index? This selection does not have (text) labeled options. So I can't use $this->select($this->byId("dt-general-input"))->selectOptionByValue(3);

1 Answer 1

1

You can use either

$this->select($this->byId("dt-general-input"))->selectOptionByLabel('Label');

Or

$this->select($this->byId("dt-general-input"))->selectOptionByValue('the option value');

For

<option value="the option value">Label</option>

For the 3rd index you'd use 2 not 3 also by the way.

If your option values are all empty and you need the 3rd one in the list, then do

// Returns an array of elements 
$allOptions = $this->select($this->byId("dt-general-input"))->options();
$thirdOpton = $allOptions[2];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the pointer. The method options() doesn't seem available for Selenium 2. But I can use selectOptionLabels() and selectOptionValues() instead.

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.