【发布时间】:2019-11-27 19:07:15
【问题描述】:
我正在尝试使用 Selenium 找到一个元素,但我没有得到它。按照 HTML 代码:
<div aria-disabled="false"
data-tb-test-id="DownloadCrosstab-Button"
role="button"
tabindex="0"
style="font-size: 12px; font-weight: normal; color: rgba(0, 0, 0, 0.7); display: inline-block; padding: 0px 24px; position: relative; text-align: center; border-style: solid; border-width: 1px; border-radius: 1px; height: 24px; line-height: 22px; min-width: 90px; box-sizing: border-box; outline: none; white-space: nowrap; user-select: none; cursor: default; background-color: rgba(0, 0, 0, 0); border-color: rgb(203, 203, 203); margin-top: 8px; width: 100%; -webkit-tap-highlight-color: transparent;"
>Tabela de referência cruzada</div>
我尝试了以下代码:
x = browser.find_element_by_id("Downloadcrosstab")
x = browser.find_element_by_link_text("Downloadcrosstab-Button")
x = browser.find_element_by_class_name('Crosstab')
但我得到了同样的错误:
NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":".Crosstab"}
(Session info: chrome=75.0.3770.142)
【问题讨论】:
-
属性
data-tb-test-id不一样id所以不能通过id获取 -
上面没有
id(更不用说一个值为Downloadcrosstab),也没有class="Crosstab",所以我不知道为什么会期望by_class_name去工作。同样,这里根本没有链接,所以按链接文本搜索也没有意义。 -
该元素没有任何 ID、任何链接文本或任何类。此外,您要查找的文本与元素中的任何内容都不匹配。
标签: python selenium xpath css-selectors webdriverwait