Thursday 22 December 2022

Most Asked Selenium Python Interview Questions and Answers?

 



If you are preparing for Selenium-Python Interview then also check below Q&A:
Python Interview Question & Answers Set - 01

Python Interview Q&A Set - 02

Python Interview Q&A Set - 03


Introduction


Python supports the Object-Oriented Programming approach to establish the applications. It is simple and easy to learn and provides lots of high-level data structures. It is an open-source language.

Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. Through Selenium Python API you can access all functionalities of Selenium WebDriver in an intuitive way.

Selenium Python bindings provide a convenient API to access Selenium WebDrivers like Firefox, Ie, Chrome, Remote etc. The current supported Python versions are 3.5 and above.

If you are new to PYTHON then first check the post on How to Install Python on windows and mac?, once installation is complete then only checkout the below Q&A

How to Configure Selenium using Python

There are following steps to configure Selenium using Python:

  • Download and install Python
  • Install Selenium libraries in Python: use "pip install selenium" command
  • Download and install PyCharm
  • Create a new project and write the Selenium test script
  • Run and validate the test scripts.

Let's start going through the Q&A:


How to start the session ?

driver = webdriver.Chrome(service=ChromeService(executable_path
=ChromeDriverManager().install()))

How to write the first Python Selenium script with Basic Commands?

Ans: Click the link HERE for the entire code 


How to use ChromeDriver ?

Download the latest chromedriver from the download page. Unzip the file:

unzip chromedriver_linux32_x.x.x.x.zip

You should see an chromedriver executable. Now you can create an instance of Chrome WebDriver like this:

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

The rest of the examples should work as given in the other documentation.

Does Selenium 2 support XPath 2.0 ?

Ref: http://seleniumhq.org/docs/03_webdriver.html#how-xpath-works-in-webdriver

Selenium delegates XPath queries down to the browser’s own XPath engine, so Selenium support XPath supports whatever the browser supports. In browsers which don’t have native XPath engines (IE 6,7,8), Selenium supports XPath 1.0 only.

How do I scroll down to the bottom of a page ?

You can use the execute_script method to execute javascript on the loaded page. You can call the JavaScript API to scroll to the bottom or any other position of a page.

Here is an example to scroll to the bottom of a page:

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

The window object in DOM has a scrollTo method is to scroll to any position of an open window. scrollHeight is a common property for all elements. document.body.scrollHeight will give the height of the entire body of the page.

How to auto save files using a custom Firefox profile?

The first step is to identify the type of file you want to auto save.

Lets understand the process with demo code and detailed steps check the Post HERE

How to upload files into file inputs ?

Ans: Select the <input type="file"> element and call the send_keys() method passing the file path, either the path relative to the test script, or an absolute path. Keep in mind the differences in path names between Windows and Unix systems.

How to use firebug with Firefox ?

First download the Firebug XPI file, later you call the add_extension method available for the firefox profile:

from selenium import webdriver

fp = webdriver.FirefoxProfile()

fp.add_extension(extension='firebug-1.8.4.xpi')
fp.set_preference("extensions.firebug.currentVersion", "1.8.4") #Avoid startup screen
browser = webdriver.Firefox(firefox_profile=fp)

Using Selenium with remote WebDriver


Ans: Click HERE to understand the steps with the demo code

How to use Implicit wait in Selenium with python?

An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find any element (or elements) not immediately available. The default setting is 0 (zero). Once set, an implicit wait is set for the life of the WebDriver object.

from selenium import webdriver

driver = webdriver.Firefox()
driver.implicitly_wait(10) # seconds
driver.get("https://automationreinvented.blogspot.com/")
myDynamicElement = driver.find_element_by_id("myDynamicElement")

How do I perform click and hold with Selenium-Python?


This method combines moving the mouse to the center of an element by pressing the left mouse button. This is useful for focusing a specific element:

clickable = driver.find_element(By.ID, "clickable")
    ActionChains(driver)\
        .click_and_hold(clickable)\
        .perform()

How to take screenshot of the current window ?

Use the save_screenshot method provided by the webdriver:

Click the link HERE with all the steps and demo code


*******************************************************************

For any doubts or career guidance, reach out to me 


********************************************************************

****************************************

TOP 15 BDD - CUCUMBER Interview Q&A


************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python


No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...