Python硒,我什么都找不到元素

问题描述 投票:0回答:1

HTML代码

<div class="dropButton" style="color: rgba(0, 0, 0, 0.87); background-color: transparent; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; box-sizing: border-box; font-family: Roboto, sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 10px, rgba(0, 0, 0, 0.23) 0px 3px 10px; border-radius: 50%; display: inline-block;"><button tabindex="0" type="button" style="border: 10px; box-sizing: border-box; display: inline-block; font-family: Roboto, sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: none; font-size: inherit; font-weight: inherit; position: relative; vertical-align: bottom; background-color: rgb(0, 188, 212); transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; height: 56px; width: 56px; overflow: hidden; border-radius: 50%; text-align: center;"><div><div style="transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; top: 0px;"><svg viewBox="0 0 24 24" style="display: inline-block; color: rgb(255, 255, 255); fill: rgb(255, 255, 255); height: 56px; width: 24px; user-select: none; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; line-height: 56px;"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path></svg></div></div></button></div>

HTML代码结束

没有iframe我得到这个错误Unable to locate element

我尝试使用此命令driver.find_element_by_xpath('//*[@id="root"]/div/div[2]/header/div/button/div/div/svg').click()

python selenium webdriver
1个回答
0
投票

也许页面使用ajax。

如果您确实确定xpath正确,则可以使用WebDriverWait。

from selenium.webdriver.support.wait import WebDriverWait

然后,

wait = WebDriverWait(driver,10,0.5)
wait.until(lambda diver:driver.find_element_by_xpath('//*[@id="root"]/div/div[2]/header/div/button/div/div/svg'))

这意味着将在10秒内每0.5秒检查一次页面中的元素。如果在此页面中,它将结束并执行下一步,否则将引发异常。

© www.soinside.com 2019 - 2024. All rights reserved.