元素不可点击(按钮被其他元素阻止)

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

Trying to click this button id="btnSearch"

我正试图点击这个按钮:browser.find_element_by_id('btnSearch')

但是这个按钮被这个div标签阻挡:<div id="actionSearch" class="row pull-right">

如果被actionSearch div阻止,我如何绕过这个带有id ='btnSearch“的按钮?

我尝试了以下方法:

  • browser.find_element_by_id('btnSearch').click()
  • browser.implicitly_wait(10) el = browser.find_element_by_xpath('//*[@id="btnSearch"]') ActionChains(browser).move_to_element_with_offset(el, 1827, 270) ActionChains(browser).click() ActionChains(browser).perform()
  • element = browser.find_element_by_id('btnSearch') browser.execute_script("arguments[0].click();", element)
  • wait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, //*[@id="btnSearch"]'))).click()

这些都不起作用。

谁能帮我这个?我花了两天时间试图点击这个按钮!请帮忙!

python html css selenium selenium-chromedriver
1个回答
0
投票

考虑提供HTML源代码的图像(提示:不提供图像,而是提供文本)我可以假设所需元素位于页面底部,您可能需要向下滚动页面才能处理它。

试试下面的代码

link = browser.find_element_by_id("btnSearch")
browser.execute_script("arguments[0].scrollIntoView()", link)
link.click()

请注意,链接不是伪元素(不在::before / ::after伪元素内),因此它不能成为您的问题的原因

至于你的代码:

ActionChains(browser).move_to_element_with_offset(el, 1827, 270)
ActionChains(browser).click()
ActionChains(browser).perform()

在这里,你试图让滚动链接到巨大的偏移,然后你点击当前的鼠标位置 - 而不是链接

您可以尝试将其修改为

ActionChains(browser).move_to_element(el)
ActionChains(browser).click(el)  # Pass WebElement you want to click as argument to `click()`
ActionChains(browser).perform()
© www.soinside.com 2019 - 2024. All rights reserved.