我正在嘗試找到包含“以下”的 div aria-label,但出現以下錯誤。
錯誤:
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //div[contains(@aria-label, 'Following' and @role='button'] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[contains(@aria-label, 'Following' and @role='button']' is not a valid XPath expression.
代碼:
unfollowuser = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@aria-label, 'Following' and @role='button']")))
我試圖找到的元素:
<div aria-label="Following @AfifRah88504204" role="button" tabindex="0" class="css-18t94o4 css-1dbjc4n r-1niwhzg r-1ets6dv r-sdzlij r-1phboty r-rs99b7 r-2yi16 r-1qi8awa r-1ny4l3l r-ymttw5 r-o7ynqc r-6416eg r-lrvibr" data-testid="1354561188005347337-unfollow" style=""><div dir="auto" class="css-901oao r-1awozwy r-18jsvk2 r-6koalj r-18u37iz r-16y2uox r-37j5jr r-a023e6 r-b88u0q r-1777fci r-rjixqe r-bcqeeo r-q4m81j r-qvutc0" style=""><span class="css-901oao css-16my406 css-bfa6kz r-poiln3 r-a023e6 r-rjixqe r-bcqeeo r-qvutc0"><span class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0">Following</span></span></div></div>
在“關注”之后,@AfifRah88504204 會隨著我使用不同的鏈接而發生變化,因此我只想找到包含“關注”文本的 div aria-label。
我究竟做錯了什么?
uj5u.com熱心網友回復:
給定的 xpath 中有一個錯字,由于缺少括號而無效。以下應該作業:
unfollowuser = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//div[contains(@aria-label, 'Following') and @role='button']")))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/391975.html
上一篇:如果包含jQuery檔案,為什么PHPPDObindParam回傳null
下一篇:Selenium與基于鉻的瀏覽器(版本1.33.106Chromium:96.0.4664.110(官方構建)(64位)
