如何等待元素可见,然后在 Python Selenium Webdriver 中单击? [英] How Can I wait for an Element will be visible then be clicked in Python Selenium Webdriver?
问题描述
在odoo中,我编写了代码来点击
In odoo I have written code to click on the send button that is
browser.find_element_by_xpath("//span[.='Send']").click()
点击这个发送按钮后,我必须点击确认销售"按钮,但在运行时它给出了一个错误,比如元素不可见
After this send button is clicked , then I have to clicked on "Confirm Sale" button , but at run time it is giving an error like Element is not visible
我也试过
webdriver.wait.until(browser.find_element_by_xpath("//span[.='Confirm Sale']"))
但它出现了像
AttributeError: 'module' object has no attribute 'wait'
我为此贴了 2 张图片
I am sticking 2 images for that
但是在这里单击发送按钮后,工作流程状态也从草稿报价"更改为已发送报价",因此,我如何等待我的网络驱动程序完成所有这些事情&然后点击确认销售"按钮
But here after send button clicked , the workflow state is also changed from "Draft Quotation" to "Quotation Sent" so , how can I wait my webdriver for all these things done & then click on "Confirm Sale" button
我已经像这样声明了我的网络驱动程序
I have declared my webdriver like this
def setUp(self):
self.browser = webdriver.Firefox()
browser = self.browser
browser.get("http://localhost:5555")
所以请给我确切的代码
推荐答案
您必须导入 webdriver 等待模块.你可以像下面的例子那样做.在 Waits
You have to import the webdriver wait module. you can do something like the example below. Read more abut waits at 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()
这篇关于如何等待元素可见,然后在 Python Selenium Webdriver 中单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!