Interview Questions Selenium Python

What is Implicit Wait in selenium python?

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
Commands to handle iframes in selenium bindings?

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 the frame
    switch_to_frame(id/name/webelement)​
  • Exit current frame
    switch_to_parent_frame()​
  • Exit all the frames
    switch_to_default_content()​
Verify whether a checkbox checked or not?

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
How to install selenium with python?
pip install selenium
How to handle javascript popups in 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
What are locators present in selenium python?

Similar to the selenium web driver, selenium bindings also have 8 locators.

  • find_element_by_name
  • find_element_by_xpath
  • find_element_by_link_text
  • find_element_by_partial_link_text
  • find_element_by_tag_name
  • find_element_by_class_name
  • find_element_by_css_selector
Handle browser windows using selenium bindings?

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

  • Get the current window handle to switch back later
    driver.current_window_handle
  • Get all the window handles
    driver.window_handles
  • Switch to the target window
    driver.switch_to_window(guid);​
Difference between close and quit in selenium python?
  • close() closes the current browser window if multiple windows are present.
  • quit() closes all the windows associated with the current session, along with closing it will also terminate the session of the driver server.
Can we perform API testing with selenium?

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.

What are navigation commands in selenium python?

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()
How to handle dropdowns in selenium python?

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)
Which IDE do you for selenium python development?

I personally prefer Eclipse with PyDev plugin for my python projects, but you can use any IDEs like Spyder, Jupiter Notebook, Enthought Canopy.

About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions