2

Trying my hands on selenium these days. When I inspect the element with firebug this is displayed as selected: None

I am not able to locate this element that has span element as None How do I locate/find this element.

  • show us the HTML code please – Yu Zhang Sep 19 '16 at 8:16
  • <a class="chosen-single" tabindex="-1"><span>None</span><div><b></b></div></a> – Rohan Kalia Sep 19 '16 at 8:18
1

You can locate this element via Xpath or Css selector without using its attribute, which it does not have any.

For example:

//a[@class='chosen-single']/span

a[class='chosen-single'] span 
| improve this answer | |
  • Still not working the xpath expression I used is: driver.findElement(By.xpath("//a[@class='chosen-single']/span")).click(); – Rohan Kalia Sep 19 '16 at 8:32
  • can you please provide the whole page's html? – Yu Zhang Sep 19 '16 at 8:54
  • <div id="id_center_chosen" class="chosen-container chosen-container-single chosen-with-drop chosen-container-active" style="width: 195px;" title=""> <a class="chosen-single" tabindex="-1"> <span>None</span> – Rohan Kalia Sep 19 '16 at 9:58
1

You can use below snippet:

driver.findElement(By.xpath("//*[@id='id_center_chosen']/span")).click();

OR

driver.findElement(By.xpath("//*[@id=\"id_center_chosen\"]/descendant::span[text()='None']")).click();
| improve this answer | |
1

Best option would be try locating the element using s Selenium IDE with Firefox. Then Navigate to Options->Format and select the language that your are working on. Then Again from the IDE click on the "Source" tab and look how Selenium IDE perform the element identification part.

| improve this answer | |
0

this could be your help

how to find int value within span class Selenium C#

try to bring exact error if possible

| improve this answer | |
0

You can try contains.Example:

//a/span[contains(text(),'None')]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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