![](/img/trans.png)
[英]Setting a value in a text field using selenium. selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:
[英]Selenium. NoSuchElementException
有人能理解這段代碼的問題是什么嗎?我知道這個問題並不新鮮,但我發現的並沒有幫助我,但也許我看起來很糟糕
wd = webdriver.Chrome('chromedriver',options=chrome_options)
wd.get('https://www.uniprot.org/uniprotkb/Q14050/entry')
sleep(15)
Molmass = wd.find_element('xpath','//*[@id="sequences"]/div/div[2]/section/ul/li[2]/div/div[2]')
HTML:
<div class="decorated-list-item__content">63,616</div>
選擇器:
#sequences > div > div.card__content > section > ul > li:nth-child(2) > div > div.decorated-list-item__content
XPATH:
//*[@id="sequences"]/div/div[2]/section/ul/li[2]/div/div[2]
錯誤:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="sequences"]/div/div[2]/section/ul/li[2]/div/div[2]"}
(Session info: headless chrome=107.0.5304.87)
我嘗試通過 class、選擇器、xpath 進行搜索,但沒有任何幫助,我嘗試設置一個計時器以便頁面有時間加載,但沒有結果
我假設您正在嘗試獲取值“ 63,616
”,因為您可以使用以下任一定位器:
CSS_選擇器:
driver.find_element(By.CSS_SELECTOR, ".sequence-container li:nth-of-type(2) .decorated-list-item__content").text
XPATH:
driver.find_element(By.XPATH, ".//section[@class='sequence-container']//li[2]//div[@class='decorated-list-item__content']").text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.