An implicit wait tells selenium binding to poll the DOM for a given amount of time when trying to find any element (or elements) if not immediately available.
Once the selenium finds the elements then selenium moves to the next command without waiting any further.
# set implicit wait time
driver.implicitly_wait(30) # seconds
Frame/ iFrame is just a web element that embeds another webpage on the current page. You can handle the iframes using the following commands. Without switching to a frame you cannot perform any action inside the frame.
switch_to_frame(id/name/webelement)
switch_to_parent_frame()
switch_to_default_content()
is_selected() function is used to check if an element is selected/checked or not. It returns a boolean value True or False. It can also be used to check if a radio button is selected.
var is_checked = driver.find_element_by_id("checkbox").is_selected()
# use the checked variable to form the logic
You can use the find_elements_* to find multiple occurrences of a selector. You should know how a link is formed to find all the links present on a web page. All the links are formed using the <a> tag, So if we find all the matches with tag name a, then we get all the links.
var totalLinks = driver.find_elements_by_tag_name("a").length
pip install selenium
You can use the driver.switch_to_alert() command to switch to an alert post that you can use the different methods for different operations.
ale = driver.switch_to_alert()
ale.accept() # accept the popup
ale.dismiss() #cancel the popup
ale.text # get the text from alert
ale.send_keys("chercher.tech") # fill the prompt text
Similar to the selenium web driver, selenium bindings also have 8 locators.
You can use switch_to_window() function to switch between the browser windows. Based on the handle you can switch between windows, the handle is nothing but a unique ID for browser windows, it will different for each window
driver.current_window_handle
driver.window_handles
driver.switch_to_window(guid);
You CANnot perform API testing with selenium python bindings but you can use the tools like request in combination with selenium to perform the API testing.
Navigation commands help the user to perform some action on the history of the browser. We can use the browser history to navigate back(), forward(), refresh()
#navigate one step back in history
driver.back()
#navigate one step forward in history
driver.forward()
# reload current page
driver.refresh()
You can use the Select class to handle the dropdowns in selenium python.
# find dropdown with Select class
sel = Select(driver.find_element_by_xpath("//select[@name='continents']"))
#select by select_by_visible_text() method
sel.select_by_visible_text("Visible text")
#select by select_by_index() method
sel.select_by_index(0)
I personally prefer Eclipse with PyDev plugin for my python projects, but you can use any IDEs like Spyder, Jupiter Notebook, Enthought Canopy.
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.