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?

3
  • what is issue?? Commented Sep 15, 2015 at 9:28
  • im unable to select the option Commented Sep 15, 2015 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 Commented May 11, 2017 at 23:24

4 Answers 4

0

Did you try to escape special symbols?

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

Try to use the next xpath:

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

4
  • Showing the same error message like " Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) " Commented Sep 18, 2015 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: Commented Sep 18, 2015 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(); Commented Sep 18, 2015 at 9:22
  • Sai, did you try code above ? Commented Sep 22, 2015 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);
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.

1
  • Both this are not working .. giving the same error invalid special characters Commented Sep 19, 2015 at 5:48

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