簡體   English   中英

硒點擊隱藏按鈕

[英]Selenium click hidden button

我想用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)

但是硒什么也不會發生,也不給出任何錯誤信息。 如何單擊帶有硒的導航菜單下的按鈕?

謝謝

如果我了解您的QuestionRequirement我們需要將Mouse HoverWebElement並將其文本作為“ Actions ,其中彈出兩個選項作為“ Request和“ 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()

您可以嘗試單擊“ 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