【问题标题】:Not able to hit the image element which works as a button in ui?无法点击在 ui 中用作按钮的图像元素?
【发布时间】:2014-04-09 18:29:49
【问题描述】:

我是使用 python 的 selenium webdriver 的新手 下面是配置:

 Selenium WebDriver: selenium-2.40.0(Python bindings)
 Python Version    : Python 2.7
 OS                : Windows

我尝试通过 xpath 和脚本中的 css 选择器点击提到的控件,但无法点击该控件。我还在 xpath 查看器中使用 xpath 对其进行了交叉检查,它在那里显示它。我也尝试过使用 css 选择器点击控件,但没有点击它。我可以使用 css 选择器和 xpath 访问网页上的其他控件。我还附加了带有 xpath 的 HTML 代码和我在代码中使用的 CSS 选择器语法。

我用于脚本的 Xpath 是:find_element_by_xpath("//img[@title='Expand All' and @alt='Expand All']")

我在脚本中使用的 css 选择器是:find_element_by_css_selector("a[class='lnk1'][onClick*='treeTable(expandAll)']")

<table width="" cellspacing="0" cellpadding="0" border="0" role="presentation">
<tbody>
 <tr>
 <td width="">
 <a class="lnk1" onfocus="" onclick="this.style.cursor='wait';document.body.style.cursor='wait'; return doTblAjax('WTableForm_453ea28b', 'action_453ea28b', 'treeTable(expandAll)', 'tableTop_453ea28b', 'action_453ea28b', 'wh', 'wa', event);" onblur="" href="/hmc/bonsai/action/T56?wh=action_453ea28b&action_453ea28b=treeTable%28expandAll%29&timestamp=144e404faf0#tableTop_453ea28b">
 <img class="tbl9" width="32" border="0" align="top" height="32" title="Expand All" src="/wclres/wcl/images/tretbl1.gif" role="button" onmouseover="className='tbl10'" onmouseout="className='tbl9'" alt="Expand All">
 </a>

【问题讨论】:

    标签: xpath selenium-webdriver css-selectors


    【解决方案1】:

    试试这个 CSS 选择器

    安全方法 css=div.someClass'] a[contains(@onclick,'treeTable(expandAll)')] > img

    这将用作展开按钮的唯一 xpath。

    谢谢!

    【讨论】:

    • 解决了..实际上我错过了一帧切换...任何方式感谢您的回复..
    猜你喜欢
    • 2021-06-29
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2013-11-17
    • 2022-10-20
    相关资源
    最近更新 更多