0

如何选择路线编号。

<table cellspacing="0" class="route__table" id="route-selection-table">
<tr class="route" route-no="12345">
                <input id="page-uuid" type="hidden" value="241e3808-fff-4564-a8e3-3232238f226a711"><td class="route__number">123459</td>
                <td class="route__name">CORPORATION LIMITED CENTRE</td>
                <td class="route__selected">
                    
                </td>
            </tr>

我正在尝试通过这个 xpath(这里的路由是动态变化的)所以我正在传递值

路线='12345'

 self.driver.find_element_by_xpath("//*[@id='route-selection-table']/tbody/[contains(text(),'" + route + "')]").click()


 selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //*[@id='route-selection-table']/tbody/[contains(text(),'12345')] because of the following error:
E       SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@id='route-selection-table']/tbody/[contains(text(),'12345')]' is not a valid XPath expression.
E         (Session info: chrome=91.0.4472.77)

..\..\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: InvalidSelectorException
4

1 回答 1

0

试试下面的 XPath-1.0 表达式:

self.driver.find_element_by_xpath("//*[@id='route-selection-table']//*[contains(text(),'" + route + "')]").click()
于 2021-06-08T16:50:11.133 回答