![](/img/trans.png)
[英]Message: no such element: Unable to locate element Selenium Python
[英]Python - Selenium (XPath) "Message: no such element: Unable to locate element"
我正在嘗試與網站互動。 我想應用一些過濾器,但出現錯誤,我的代碼無法識別 xpath。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
options=Options()
options.add_argument('--windoes-size=1920,1080')
driver=webdriver.Chrome(options=options)
driver.get("https://dexscreener.com/polygon/uniswap")
folder=driver.find_element(By.XPATH,'//button[@class="chakra-button chakra-menu__menu-button custom-tpjv8u"]')
folder.click()
folder=driver.find_element(By.XPATH,'//button[@id="menu-list-36-menuitem-33"]')
folder.click()
您應該使用另一個 XPATH 進行選項選擇。 似乎選項的 ID 可能是動態生成的。
因此,您可以嘗試使用不同過濾器的 XPATH:
//button[@value="m5"] # Last 5 minutes button
//button[@value="h1"] # Last hour
//button[@value="h6"] # Last 6 hours
//button[@value="h24"] # Last 24 hours
這樣對我來說效果很好。
您是否嘗試過使用 CSS_SELECTOR? 我最近在使用 Selenium,有時當 XPATH 不起作用時,CSS_SELECTOR 起作用了。
folder=driver.find_element(By.CSS_SELECTOR, "selector here")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.