【问题标题】:What element values should i select in order to click the element [duplicate]我应该选择什么元素值才能单击元素[重复]
【发布时间】:2019-05-29 06:27:14
【问题描述】:

这里是sn-p的html代码:

<div autoid="" buttondecorator="" class="ideas-card _ngcontent-zty-5 collapsed-card" aria-label="Find new keywords" aria-expanded="false" aria-describedby="F7C56A74-5C67-4B02-B3E2-AFD3DFBA318B--0" aria-hidden="false" id="F49F12F8-6C5C-4567-AAD9-6C76A52FD801--0" tabindex="0" role="button" aria-disabled="false"></div>

从上面的 sn-p 代码来看,它是一个卡片元素,我正在尝试使用 selenium python 单击该元素。

我的代码是:

find_new = browser.find_element_by_xpath("//div[@aria-label='Find new keywords']").click()

还有其他方法可以选择该元素吗?

我得到的错误信息是:

element not interactable
  (Session info: chrome=74.0.3729.169)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.16299 x86_64)

【问题讨论】:

  • 我的 html sn-p

标签: javascript python selenium-chromedriver


【解决方案1】:

您可能需要等待元素变为可点击后才能点击它。使用 WebDriverWait 和预期条件:

from selenium.webdriver.support import expected_conditions

find_new = WebDriverWait(driver, 20).until(
 expected_conditions.presence_of_element_located((By.XPATH, "//div[@aria-label='Find new keywords']")).click()

您可能会尝试的另一个技巧是使用 JavaScript Executor:

find_new = browser.find_element_by_xpath("//div[@aria-label='Find new keywords']")
browser.execute_script("arguments[0].click();", find_new)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 2018-11-07
    • 2017-12-23
    相关资源
    最近更新 更多