DevLabs Alliance - WhatsApp
DevLabs Alliance Logo

Q1. What will happen if you mix both implicit wait and explicit wait in a Selenium Script?

According to the official Selenium documents, it is being suggested not to mix both Implicit and Explicit Waits. If we mix both of them, then it can cause unpredictable wait times.


Implicit wait is defined only once in the code, and it will remain the same throughout the driver object instance.


Explicit wait is defined wherever it is necessary in the code, and it will call at the time of execution. Explicit wait will overwrite the implicit wait if applied in the code. So, Explicit Wait always gets first preference and the then Implicit Wait is executed.

Q2. What is MaxSession Properties in Selenium Grid?

MaxSession is defined as a number of browsers, independent of the type & version, can run in parallel on the remote machine.


MaxSession overrides the Max Instances settings and hence can restrict the number of browser instances that can run in parallel.


For eg.

If maxSession=1 then only a single browser will run in remote machine. If maxSession=2 then any two browsers can run at a time irrespective of Max Instances that we defined. It can be either 2 Internet Explorer or 2 FireFox or 1 Internet Explorer and 1 Firefox.


browser browserName=firefox,maxInstances=5,maxSession=2

Q3. What will happen if you run this command. driver.get(“www.devlabsalliance.com”) ; ?

Since the given URL doesn’t contain http or https prefix, hence it will throw an exception.

So, it is required to pass HTTP or HTTPS protocol within driver.get() method.


driver.get(“https://www.devlabsalliance.com”);

Q4. What is MaxInstances Properties in Selenium Grid?

MaxInstances is defined as the number of browser instances of the same version of the browser that can run on the remote machine.


for eg.

-browser browserName=InternetExplorer,version=11,maxInstances=3,platform=WINDOWS

-browser browserName=Firefox,version=12,maxInstances=2,platform=WINDOWS

This will allow to run 5 instances (3 instances of IE and 2 instances of Firefox) at the same time in a remote machine.

Q5. What is Max Session Properties in Selenium Grid?

MaxSession is defined as a number of browsers, independent of the type & version, can run in parallel on the remote machine.


MaxSession overrides the MaxInstances settings and hence can restrict the number of browser instances that can run in parallel.


For eg.

If maxSession=1 then only a single browser will run in remote machine. If maxSession=2 then any two browsers can run at a time irrespective of MaxInstances that we defined. It can be either 2 Internet Explorer or 2 FireFox or 1 Internet Explorer and 1 Firefox.


browser browserName=firefox,maxInstances=5,maxSession=2

Q6. How can we handle Web-based Pop-ups or Alerts in Selenium?

Web-based alerts or popups are handled by switching to the alert window and calling Selenium WebDriver Alert API methods.


Below methods are called for various actions:


  • dismiss(): To click on Cancel button.
  • accept(): To Click on OK button.
  • getText(): To get the text which is present on the Alert.
  • sendKeys(): To enter the text into the alert box

Q7. What happen if you mix both Thread. Sleep and WebDriver Waits in a Selenium Script ?

Thread.sleep() method is used to pause the execution of the script for a specified time in milliseconds.


If WebDriver waits are used along with thread.sleep() method, then WebDriver will hold the execution for a specified time (as mentioned in thread.sleep()) and then will follow other wait. If we mix both the waits, then test execution time will increase.

Q8. How can you use the Recovery Scenario in Selenium WebDriver?

Recovery Scenarios are used by using “Try Catch” block within Selenium WebDriver Java tests.


try{
driver.get(“https://www.devlabsalliance.com“);
}
catch{
System.Out.println(e.getMessage());
}

Q9. What is Robot Class in Selenium and what are its advantages?

Robot Class is used to control the keyboard or mouse to interact with Operating System windows like download pop-ups, alerts, print pop-ups, etc. or native OS applications like Notepad, Calculator, Skype, etc. while doing browser automation.


The various advantages of Robot Class are:


  • It simulates Mouse and Keyboard events.
  • It helps in upload/download of files while using Selenium WebDriver.
  • It gets easily integrated with current automation framework (keyword-driven, data-driven or hybrid framework).

Q10. What are various Robot Class internal methods and explain their usage?

Some of the Robot Class Internal methods and their usage are as follows:


  • keyPress(): e.g. : robot.keyPress(KeyEvent.VK_Down) : This method will press down the arrow key of keyboard.
  • mouseMove(): e.g. robot.mouseMove(point.getX(), point.getY()) : This will move the mouse pointer to specific X and Y coordinates.
  • mousePress(): e.g. robot.mousePress(InputEvent.BUTTON_DOWN_MASK): This method will press the right click of mouse.
  • mouseRelease(): e.g. robot.mouseRelease(InputEvent.BUTTON_DOWN_MASK): This method will release the right click of mouse.
  • keyRelease(): e.g. robot.keyRelease(KeyEvent.VK_DOWN): This method will release the down arrow key of keyboard.


👉Selenium Professional Training

👉Certified SDET Professional Training

Q11. How to upload a file in Selenium WebDriver?

We can upload a file in Selenium WebDriver using the AutoIT script. Follow the following steps for uploading a file with AutoIT script:


  • Download and Install the “AutoIT”.
  • Open Eclipse and write code through Selenium WebDriver for clicking on the “Upload File” button.
  • Ensure FileUpload.exe is generated after compilation in the location where AutoIT is installed. This FileUpload.exe already contains the file(say, devLabsAlliance.docx) to be uploaded, and this is pre-configured through AutoIT editor.
  • After click of Upload button, AutoIT script needs to be called and then control immediately transferred to AutoIT in order to upload a file and then control is sent back to Selenium.


  • Syntax for calling AutoIT script:
  • Runtime.getRuntime().exec(“D:\\AutoIT\\FileUpload.exe”);

Q12. How to run Selenium test from Command Line in Selenium WebDriver?

For doing this, we need to install Testing, and need to set the class-path.


Follow the below steps:


  • Create testng.xml file and store this XML file into project home directory.
  • Ensure that you put all the Selenium jars in separate folder and keep that folder into project home directory.
  • Open Command Prompt and type CD\ and then press Enter.
  • Now copy the path of your project home directory in this CD directory path and then press Enter.
  • Now set the class path for this and specify the bin folder.
  • Project Directory > set class path=Project Directory\bin; and press enter
  • Now specify the folder(say, lib) where all the jars are available.
  • Project Directory > set classpath=Project Directory\lib\*; and press enter
  • Now run xml file using below command:
  • Project-directory > java org.testing.TestNG.xml and hit Enter.

Q13. How to connect a database in Selenium?

To connect a database in Selenium, we use JDBC driver while using Java Programming language.


Follow the below steps to connect database in Selenium:


  • Load the required JDBC driver class.
  • Class.forName(“net.sourceforge.jtds.jdbc.Driver”);
  • Establish a connection to the database:
  • Connection con = DriverManager.getConnection(“DataBaseURL”, “userName”, “password”);
  • Connection URL:
  • jdbc:sqlserver://ipAddress:portNumber/dbName
  • Execute SQL Queries:
  • Statement sqlStatement = con.createStatement();
  • String sqlQuery = “SELECT * FROM table_name WHERE condition”
  • ResultSet resSet = sqlStatement.executeQuery(sqlQuery);
  • Fetching data from resultSet:
  • while (resSet.next()) {
  • System.out.println(resSet.getString(required_column_name));}
  • Closing the database connection. con.close();

Q14. How to Scroll Web Page Down Or Up Using Selenium WebDriver?

To scroll the page Up or Down, JavaScript scrollBy() method is used.


Syntax for Scrolling WebPage down:


WebDriver driver = new ChromeDriver();driver.navigate().to(“https://www.devlabsalliance.com”);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollBy(0, 250)”, “”);

Syntax for Scrolling WebPage Up:

WebDriver driver = new ChromeDriver();driver.navigate().to(“https://www.devlabsalliance.com”);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollBy(0, -250)”, “”);

Q15. What are Desired Capabilities?

Desired capabilities are used in to handle SSL certificates in Chrome browser.


To achieve this, we need to create an instance of Desired Capabilities:

DesiredCapabilities desiredCapability = DesiredCapabilities.chrome();

Q16. How to Highlight Element Using Selenium WebDriver?

We can highlight the specified element using JavaScriptExecuter interface.


WebDriver driver = new ChromeDriver();
driver.get(“https://www.devlabsalliance.com”);
WebElement ele = driver.findElement(By.xpath(“//*[@id=’devLabs’]”));
JavascriptExecutor js = (JavascriptExecutor) driver;
//Passing values based on css style. Yellow background color with solid red color border.
js.executeScript(“arguments[0].setAttribute(‘style’, ‘background: yellow; border: 3px solid red;’);”, ele)

Q17. How to launch a batch file in a Selenium webdriver?

Before starting the automation, we need to set up the prerequisites in a test suite to run a batch file or an executable file.


Below code can be used for the same:


Process batchFile = Runtime.getRuntime.exec(“Path of batch file”);
batchFile.waitFor();

Q18. How Selenium Webdriver test can be run from the command line?

Below code is used to write Selenium WebDriver test using command line:


java -classpath “.;selenium-server-standalone-2.33.0.jar” ExampleClass

Q19. Which Selenium technology is useful for distributed data processing?

Selenium Grid is popularly used for distributed data processing. Selenium Grid distributes tests on multiple machines in parallel.


The tests can be executed in parallel on different operating systems and different web browsers at the same time with a single script using Selenium Grid.


Distributed data processing in Selenium reduces overall time of execution, and feedback is also quick in distributed data process.


Explain what the following snippet of Java code does in brief:


WebElement example = driver.findElement(By.xpath(“//*[contains(text(), ‘data’)]”));


The above code is defining a variable ‘example’ of type Web Element, and it is initializing it with a reference to an element that contains the text value “data” using XPath search.

Q20. What is StaleElementException?

StaleElementException is an exception which is thrown when the element that is invoked is no longer attached to the DOM(Document Object Model) for any reason.


For eg. If the element found in a web page is referenced as a Web Element in the WebDriver. Now if the DOM changes, then Web Element is no longer available, hence Web Element goes stale. Then, if we try to interact with this stale element, then the StaleElementException is thrown.


👉Selenium Professional Training

👉Certified SDET Professional Training

Meet The Author

DevLabs Alliance Blogs Author

Admin


Author


DevLabs Alliance Blogs Twitter IdDevLabs Alliance Blogs linkdinDevLabs Alliance Blogs instagram

Author Bio

DevLabs Alliance conducts career transformation workshops & training in Artificial Intelligence, Machine Learning, Deep Learning, Agile, DevOps, Big Data, Blockchain, Software Test Automation, Robotics Process Automation, and other cutting-edge technologies.

INQUIRY

Want To Know More


Email is valid



Phone


By tapping continuing, you agree to our Privacy Policy and Terms & Conditions

“ The hands-on projects helped our team put theory into practice. Thanks to this training, we've achieved seamless collaboration, faster releases, and a more resilient infrastructure. ”
DevLabs Alliance Blogs Page Review
Vijay Saxena

SkillAhead Solutions

Lets get started today!

and get that DREAM JOB

DevLabs Alliance Footer section
DevLabs Alliance LinkedIn ProfileDevLabs Alliance Twitter ProfileDevLabs Alliance Facebook ProfileDevLabs Alliance Facebook Profile
DevLabs Alliance Logo

USA

1603, Capitol Avenue, Suite 413A, 2659, Cheyenne, WY 82001, USA

DevLabs Alliance ISO 9001

DevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer Section

`Copyright © DevLabs Alliance. All rights Reserved`

|

Refund & Reschedule Policy

Privacy Policy

Terms of Use