【问题标题】:Selenium Python select the link from 3rd column from a tableSelenium Python 从表的第 3 列中选择链接
【发布时间】:2016-02-12 00:13:11
【问题描述】:

我有一个包含一些行和列的表格的页面。第一列有一个复选框(索引为 0)。第二列有名称。第 3 列有一个名为 view 的链接。表中有几行数据。 我想单击名称为“Selenium_CRM_For_Edit_Test”的查看链接 该名称可以在行表中的任何位置。

我可以使用以下 XPATH 来识别列名:

//span[contains(., "Selenium_CRM_Edit_Test")]

我不知道如何到达具有查看链接的下一列

我尝试了以下 XPath:

//span[contains(., "Selenium_CRM_Edit_Test")]/../preceding-sibling::td/div/span[contains(text(), "view")]

那行不通。我以为前兄弟会下一个 TD 元素

HTML sn-p 是:

<table id="data_configuration_data_previews_ct_fields_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
    <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="0">
    <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="1">
    <tr class="GJPPK2LBFG GJPPK2LBMG" __gwt_subrow="0" __gwt_row="18">
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG GJPPK2LBNG">
        <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBNG">
            <div __gwt_cell="cell-gwt-uid-237" style="outline-style:none;">
                <span class="linkhover" title="Selenium_LADEMO_CRM_DONOTCHANGE" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Selenium_CRM_For_Edit_Test</span>
            </div>
        </td>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBNG">
        <div __gwt_cell="cell-gwt-uid-238" style="outline-style:none;">
            <span class="linkhover" title="view" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">view</span>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBNG">
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH GJPPK2LBNG">
    </tr>
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="19">
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="20">
</tbody>

如何访问名为 Selenium_CRM_For_Edit_Test 的链接?

谢谢, 里亚兹

【问题讨论】:

    标签: python-2.7 selenium xpath selenium-webdriver


    【解决方案1】:

    假设你要定位

    <span class="linkhover" title="view" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">view</span>
    

    元素,基于文本

    <span class="linkhover" title="Selenium_LADEMO_CRM_DONOTCHANGE" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Selenium_CRM_For_Edit_Test</span>
    

    您可以使用following 轴:

    //span[contains(., "Selenium_CRM_Edit_Test")]/following::span[@class="linkhover"]
    

    【讨论】:

    • 我设法使用这个 Xpath 来获取视图链接: //span[@title = 'Selenium_CRM_Edit_Test']/ancestor::tr[1]/td[3]//span[contains(文本(),“视图”)]
    • 你的会更好。我会用那个。谢谢
    猜你喜欢
    • 2011-10-12
    • 2017-05-25
    • 2018-01-25
    • 1970-01-01
    • 2019-05-03
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    相关资源
    最近更新 更多