使用 xpath 告诉 selenium 在哪里点击? [英] using xpath to tell selenium where to click?

查看:20
本文介绍了使用 xpath 告诉 selenium 在哪里点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这一切的新手,但不久前我已经了解了一些关于 python 的东西,你能帮我指定正确的硒点击 XPath 吗?

我试过这种方式,但没有奏效,很明显:(

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

如果你想知道我从哪里得到那个丑陋的 XPath,它来自 Firebug 的复制 XPath 选项.

我认为 HTML 代码段和地狱一样长,所以我无能为力:

<身体><div id="outer_wrapper"><div id="容器"><div id="标题"><div id="menunav"><ul><li><a title="登录页面" href="[dest]">登录</a></li><li><a title="" href="[dest]">站点地图</a></li>**<li><a title="" href="[dest]">管理</a></li>**

</html>

解决方案

以下是一些示例定位器,可用于单击 Administration 链接(基于您的 XPath 和 HTML 代码段).正确的 Selenium 命令是 click.

我希望这为您指明了正确的方向.

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>

解决方案

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.

I hope this points you in the right direction.

这篇关于使用 xpath 告诉 selenium 在哪里点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
Python最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆