views:

84

answers:

1

I'm new to all of this but I've learned a few things about python not long time ago, could you help me specify the correct the XPath for selenium to click?

I've tried this way, but didn't work, obviously :(

self.selenium.click("xpath=//html/body/div/div/div/div[4]/ul/li[3]/a")

If you're wandering where did i get that ugly XPath, it's from Firebug's copy XPath option.

I think that the HTML snippet is as long as hell so i couldn't do more than this:

<html>
  <body>
    <div id="outer_wrapper">
      <div id="container">
        <div id="header">
          <div id="menunav">
            <ul>                                
              <li><a title="Login page" href="[dest]">Login</a></li>                              
              <li><a title="" href="[dest]">Sitemap</a></li>
              **<li><a title="" href="[dest]">Administration</a></li>**
            </ul>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>
+1  A: 

Below are a few example locators you could use to click the Administration link (based on your XPath and HTML snippet). The correct Selenium command is click.

  • link=Administration
  • css=a:contains(Administration)
  • css=#menunav a:nth-child(3)
  • xpath=id('menunav')/descendant::a[3]
  • //a[text()='Administration']
  • //a[contains(text(), 'Administration')]

I hope this points you in the right direction.

Dave Hunt
thanks dave, but i still don't get why you use the text() method that way, shouldn't be text('administration') ?
decebal
You're right that you don't need to use `contains` in this case. You can use `//a[text()='Administration']` instead.
Dave Hunt