1

My HTML code:

<select id="selectrepo" class="col-md-5 col-md-offset-1 select ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" ng-required="true" ng-model="locFrmdata" ng-disabled="!locPathdet" name="select" required="required">

<option id="dfltval" selected="selected" value="">Kiezen</option>

<option id="locDet+'0'" class="ng-binding ng-scope" value="\keur\BVGO" ng-repeat="locationDet in childRepos track by $index">\keur\BVGO</option>
</select>

This is the WebDriver code I'm writing:

String repos =  new String("\keur\BVGO");
Select repo = new Select(driver.findElement(By.id("selectrepo")));
repo.selectByVisibleText(repos);

and also

repo.selectByValue("\keur\BVGO");
repo.selectByVisibleText("\keur\BVGO");

How do I find this element?

  • what is issue?? – Helping Hands Sep 15 '15 at 9:28
  • im unable to select the option – sai viswanath Sep 15 '15 at 11:16
  • 3
    I'm voting to close this question as off-topic because is about software engineering and is also abandoned by one-time user – Michael Durrant May 11 '17 at 23:24
0

Did you try to escape special symbols?

repo.selectByVisibleText("\\keur\\BVGO");
| improve this answer | |
  • repo.selectByVisibleText("\\\keur\\\BVGO"); .. I tried this but not working .. – sai viswanath Sep 16 '15 at 4:15
  • repo.selectByVisibleText("\\\keur\\\BVGO"); .. Show error message like " Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) " – sai viswanath Sep 16 '15 at 4:46
  • sorry, I meant two slashes. did yo try two slashes ? – Ostap Elyashevskyy Sep 16 '15 at 12:17
  • yes, i have tried with two slashes also !! .. But didn't work – sai viswanath Sep 16 '15 at 12:47
0

Try to use the next xpath:

driver.findElement(By.xpath("//select[@id='selectrepo']/option[text()='\\keur\\BVGO']")).click();

| improve this answer | |
  • Showing the same error message like " Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) " – sai viswanath Sep 18 '15 at 5:15
  • try again, I have updated with extra slashes. I have deployed html you provided on IIS and tested wit Java and Python API and it works for me: – Ostap Elyashevskyy Sep 18 '15 at 9:20
  • I have tested these lines and they select proper value every time: driver.findElement(By.xpath("//select[@id='selectrepo']/option[text()='\\keur\\BVGO']")).click(); driver.findElement(By.xpath("//select[@id='selectrepo']/option[text()='Kiezen']")).click(); driver.findElement(By.xpath("//select[@id='selectrepo']/option[text()='\\keur\\BVGO']")).click(); – Ostap Elyashevskyy Sep 18 '15 at 9:22
  • Sai, did you try code above ? – Ostap Elyashevskyy Sep 22 '15 at 9:26
0

The below code works for me:

Select dropdown = new Select(driver.findElement(By.id("selectrepo")));
dropdown.selectByValue("\\keur\\BVGO");

You can also use selectByIndex for selecting the value;

Select dropdown = new Select(driver.findElement(By.id("selectrepo")));
dropdown.selectByIndex(1);
| improve this answer | |
0

Why do you not use following:

repo.selectByVisibleText('\keur\BVGO');

OR

driver.findElement(By.xpath("//select[@id='selectrepo']/option[text()='\keur\BVGO']")).click();

Only single quotes disables interpolation.

| improve this answer | |
  • Both this are not working .. giving the same error invalid special characters – sai viswanath Sep 19 '15 at 5:48

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