Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I have also tried

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

but it arises an error like

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

I am sticking 2 images for that before Send button image - it's a wizard After send button , wizard will be closed & then have to click on confirm sale button

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")

so please provide me exact code for that

like image 313
sakib keriwala Avatar asked Sep 04 '15 13:09

sakib keriwala


People also ask

How do you add wait until element is visible in Selenium?

The solution is, of course, to instruct Selenium to wait until the desired element is visible before trying to interact with it. var wait = new WebDriverWait(driver, TimeSpan.

What would you use if you are waiting for an element to be clickable in Selenium?

#1) elementToBeClickable() – The expected condition waits for an element to be clickable i.e. it should be present/displayed/visible on the screen as well as enabled. wait. until(ExpectedConditions.

How can you find if an element is displayed on the screen in Selenium?

New Selenium IDE We can verify whether an element is present or visible in a page with Selenium webdriver. To check the presence of an element, we can use the method – findElements. The method findElements returns a list of matching elements. Then, we have to use the method size to get the number of items in the list.


1 Answers

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()
like image 61
Amit Verma Avatar answered Nov 14 '22 23:11

Amit Verma