c# - Find element in Selenium using XPATH or CSS Selector -


i m trying find element "import" using selenium webdriver in c#. have tried following codes nothing find it.

driver.findelement(by.xpath("//*[@class='menu_bg']/ul/li[3]")).click(); driver.findelement(by.xpath("//*[@id='import']/a")).click(); driver.findelement(by.cssselector("#import>a")).click(); driver.findelement(by.xpath("//*[@class='menu_bg']/ul/li[3]/a")).click(); driver.findelement(by.cssselector("ul[@class='menu_bg']>li[value='3']")).click(); 

please me out. design page looks below:

<body>     <div class="header_bg"></div>     <div class="menu_bg">         <ul class="menu">             <li id="retrieve"></li>             <li id="scan" class="test"></li>             <li id="import">                 <a target="main" href="import/import.aspx" onclick="clickme(this,'import')">import</a>             </li>             <li id="admin"></li>             <li id="help"></li>             <li style="float: right;"></li>         </ul>     </div>  </body> 

all time got error below:

unable find element 

xpath indexers 1-based, opposed other languages whereby 0-based.

this means targetting 2nd li element, has no anchor element.

so:

//*[@class='menu_bg']/ul/li[3]/a 

however, xpath query not great , strict on position - although newly fixed xpath above should work, i'd advise think of else.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -