当前位置: 动力学知识库 > 问答 > 编程问答 >

css selectors - Not able to click on dropdown through xpath or CSS?

问题描述:

This is a dropdown which I am not able to click through xpath or CSS selector.

My HTML code:-

<button class="userInfo dropdown-toggle btn btn-default" data-reactid=".0.0.0.1:$=11:$1.1" type="button"> <span class="sr-only" data-reactid=".0.0.0.1:$=11:$1.1.0">Toggle dropdown</span> <span class="caret" data-reactid=".0.0.0.1:$=11:$1.1.1"/> <span data-reactid=".0.0.0.1:$=11:$1.1.2" style="letter-spacing:-.3em;"/>

Code I have tried:-

driver.findElement(By.xpath(".//*[@data-reactid='.0.0.0.1:$=11:$1.1']")).click()‌​;

but I am getting error says:-

it can not find such xpath

网友答案:

There may be a possiblity of iframe:-

driver.switchTo().frame("provide frame name or location");

Refer below for more info regarding switch on frame:-

http://toolsqa.com/selenium-webdriver/handling-iframes-using-selenium-webdriver/

OR

There is a possiblity that your xpath is not fine or returning more than 1 element to selenium. In this condition selenium will be confuse that on which element selenium should click . so check your xpath again

Hope it will help you :)

分享给朋友:
您可能感兴趣的文章:
随机阅读: