【问题标题】:Selenium click hidden buttonSelenium 点击隐藏按钮
【发布时间】:2017-12-18 19:57:55
【问题描述】:

我想用 selenium 和 python 控制网页

Python 代码;

menu = browser.find_element_by_css_selector(".nav")
hidden = browser.find_element_by_link_text('Soluton')
element = browser.find_element_by_xpath("//div[@class=\"two-columns\"]")
Option 1: ActionChains(browser).move_to_element(menu).click(hidden)
Option 2 : ActionChains(browser).move_to_element(element).click(hidden)

html代码;

我想点击导航菜单下的“解决方案”按钮。

但是,解决方案位于导航菜单下。所以它被隐藏了。

所以,我输入以下代码;

 选项 1:

ActionChains(browser).move_to_element(menu).click(hidden)

 选项 2:

ActionChains(browser).move_to_element(element).click(hidden)

但是 selenium 不会发生任何事情,也不会给出任何错误消息。 如何使用 selenium 单击导航菜单下的按钮?

谢谢

【问题讨论】:

  • 虽然我不完全确定,但从我可以通过 html 猜测的内容来看,您可能必须单击 .icon-ellipsis-h 才能使子操作菜单可见。不过真的不能说太多,因为我假设大多数悬停可见性的东西都是通过该页面上的 javascript 控制的。
  • @WiggyA。谢谢。我试着只找到

标签: python selenium selenium-webdriver


【解决方案1】:

如果我理解您的Question 和您的Requirement,我们需要Mouse Hover 覆盖WebElement,文本为Actions,其中2 个选项弹出为@ 987654326@Solution 以及您想在 Solutionclick()。为此,您可以使用以下代码块:

#import
from selenium.webdriver.common.action_chains import ActionChains
#code block
menu = driver.find_element_by_xpath("//a[@class='incident-action']/i[@class='icon-ellipsis-h']")
ActionChains(driver).move_to_element(menu).perform()
driver.find_element_by_xpath("//div[@class='action-list' and @id='header-actions-list']//a[@class='icon-arrow' and contains(text(),'Solution')]").click()

【讨论】:

    【解决方案2】:

    您可以尝试单击Actions 使操作列表可见,然后单击所需的Solution 选项:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait as wait
    from selenium.webdriver.support import expected_conditions as EC
    
    actions = wait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Actions")))
    actions.click()
    solution = wait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Solution")))
    solution.click()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 2015-08-21
      相关资源
      最近更新 更多