簡體   English   中英

我如何等待元素可見,然后在Python Selenium Webdriver中單擊?

[英]How Can I wait for an Element will be visible then be clicked in Python Selenium Webdriver?

在odoo中,我編寫了代碼來點擊發送按鈕

browser.find_element_by_xpath("//span[.='Send']").click()

單擊此發送按鈕后,我必須單擊“確認銷售”按鈕,但在運行時它會給出一個錯誤,如元素不可見

我也試過了

webdriver.wait.until(browser.find_element_by_xpath("//span[.='Confirm Sale']"))

但它出現了一個錯誤

AttributeError: 'module' object has no attribute 'wait'

我堅持2張圖片 在發送按鈕圖像之前 - 它是一個向導 發送按鈕后,向導將關閉,然后必須單擊確認銷售按鈕

但是點擊發送按鈕后,工作流狀態也從“草稿報價”更改為“報價發送”,所以,如何等待我的webdriver完成所有這些操作,然后點擊“確認銷售”按鈕

我已經宣布我的webdriver是這樣的

def setUp(self):
    self.browser = webdriver.Firefox()
    browser = self.browser
    browser.get("http://localhost:5555")

所以請為我提供准確的代碼

您必須導入webdriver等待模塊。 你可以做類似下面的例子。 Waits閱讀更多等待

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

wd = webdriver.Chrome(executable_path="your/path/to/chromedriver")

# Access website

wait = WebDriverWait(wd, 10)
confirm = wait.until(EC.element_to_be_clickable((By.XPATH, "//span[.='Confirm Sale']")))
confirm.click()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM