简体   繁体   English

硒点击隐藏按钮

[英]Selenium click hidden button

I want to control webpage with selenium and python 我想用Selenium和python控制网页

Python code; 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 code; html代码;

请访问此图片

I want to click "Solution" button under the nav menu. 我想单击导航菜单下的“解决方案”按钮。

However, Solution be in under the nav menu. 但是,解决方案位于导航菜单下。 So it's hidden. 所以它是隐藏的。

so, I type following codes ; 所以,我输入以下代码;

Option 1: 选项1:

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

Option 2 : 选项2:

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

But selenium not happen anything and not give any error message. 但是硒什么也不会发生,也不给出任何错误信息。 How can I click a button under nav menu with selenium ? 如何单击带有硒的导航菜单下的按钮?

Thanks 谢谢

If I have understood your Question and your Requirement we need to Mouse Hover over the WebElement with text as Actions where 2 options pops out as Request and Solution and you want to click() on Solution . 如果我了解您的QuestionRequirement我们需要将Mouse HoverWebElement并将其文本作为“ Actions ,其中弹出两个选项作为“ Request和“ Solution并且您要在“ Solutionclick() To achieve that you can use the following code block : 为此,可以使用以下代码块:

#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()

You can try to click Actions to make actions list visible and then click on required Solution option: 您可以尝试单击“ 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM