在python上使用Selenium查找按钮

2024-06-28 15:06:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从此按钮检索数据,但它引发了以下错误:selenium.common.exceptions.elementnotinteractiableexception:Message:element notinteractiable

按钮源代码:

<button class="Blockreact__Block-sc-1xf18x6-0 Buttonreact__StyledButton-sc-glfma3-0 bqHBns jFqMrE ActionButtonreact__StyledButton-sc-7jpoey-0" type="button"><div class="Blockreact__Block-sc-1xf18x6-0 Flexreact__Flex-sc-1twd32i-0 olSpy jYqxGr"><i value="add" size="24" class="Iconreact__Icon-sc-1gugx8q-0 irnoQt material-icons">add</i></div></button>

我的代码:

browser.find_element_by_xpath("//button[@type='button']")

页面:在https://opensea.io/asset/create上添加项目 enter image description here

enter image description here


Tags: 数据divaddtypeselenium错误buttonelement
2条回答

单击按钮而不是图标。xpath:

.//body/div[1]/div[1]/main/div/div/section/div[2]/form/section[6]/div[1]/div/div[2]/button 

您还可以使用elementwaits包来确保按钮首先是可交互的

wait.until(ExpectedConditions.visibilityOfElementLocated(by));
wait.until(ExpectedConditions.elementToBeClickable(by));

然后点击

因为浏览器不适合你

你试过ActionsChains吗

from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(browser.find_element_by_xpath("//i[@value='add']/../..")).click().perform()

相关问题 更多 >