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.

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

5 Answers 5

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 
3
  • Still not working the xpath expression I used is: driver.findElement(By.xpath("//a[@class='chosen-single']/span")).click(); Commented Sep 19, 2016 at 8:32
  • can you please provide the whole page's html?
    – Yu Zhang
    Commented Sep 19, 2016 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> Commented Sep 19, 2016 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();
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.

0

this could be your help

how to find int value within span class Selenium C#

try to bring exact error if possible

0

You can try contains.Example:

//a/span[contains(text(),'None')]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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