【问题标题】:Find button with Selenium on python在 python 上使用 Selenium 查找按钮
【发布时间】:2021-08-14 14:02:42
【问题描述】:

我正在尝试从此按钮检索数据,但它引发了以下错误:selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

按钮源代码:

<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上添加项目

【问题讨论】:

  • 您的浏览器是否全屏启动?
  • 不,我没有尝试全屏。我应该吗?
  • 是的,试试它可能会解决您的问题
  • 即使 selenium 的其他功能有效?
  • 尝试使用full xpath;告诉我结果

标签: python python-3.x selenium selenium-chromedriver


【解决方案1】:

因为浏览器最大化不适合你。

你尝试过 ActionsChains 吗?

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

【讨论】:

  • 感谢您的回答,但它仍然引发 selenium.common.exceptions.NoSuchElementException:Message: no such element: Unable to locate element: {"method":"xpath","selector":" //button[@type='button' and text()='add']"}
  • 好吧,早些时候我们遇到了selenium.common.exceptions.ElementNotInteractableException: 错误,看起来我们已经克服了这个问题,但现在有了NoSuchElementException:Message for //button[@type='button' and text()='add'],我需要查看您的 HTML。你能分享相关的 HTML,我看到你已经分享了,但你能分享更多的外部 HTML 吗?
  • 好的,您可以尝试使用此 xpath 代替 //i[@value='add']/../.. 吗,请参阅上面的更新。
  • 抱歉这么晚才回答,顺便说一句,我收到这个错误:selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (1312, 1177) is out of bound of viewport width (1920) and height (1080)
  • 我差点忘了这个问题,能给个网址吗?
【解决方案2】:

点击按钮而不是图标。路径:

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

您也可以使用元素等待包来确保按钮首先是可交互的

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

然后点击

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多