Home / Interview /Advanced Selenium I...
Admin
2023-09-07
0 mins read
Similar Blogs
What is Selenium Testing?
0 mins read
2023-09-13
XPath in Selenium
0 mins read
2023-09-13
Everything You Should Know About Waits in Selenium
0 mins read
2023-09-13
How do I automate in Selenium?
0 mins read
2023-09-07
How To Automate Database Testing Using Selenium and JDBC?
0 mins read
2024-06-07
What Is Test Automation Framework?
0 mins read
2023-09-07
What is Selenium webdriver?
0 mins read
2024-03-29
Setup Selenium with C# Step By Step Tutorial
0 mins read
2023-09-13
What Is Parallel Testing In Selenium?
0 mins read
2023-09-08
How To Do Cross Browser Testing In Selenium?
0 mins read
2023-09-08
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.
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
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”);
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.
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
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:
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.
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()); }
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:
Some of the Robot Class Internal methods and their usage are as follows:
We can upload a file in Selenium WebDriver using the AutoIT script. Follow the following steps for uploading a file with AutoIT script:
For doing this, we need to install Testing, and need to set the class-path.
Follow the below steps:
To connect a database in Selenium, we use JDBC driver while using Java Programming language.
Follow the below steps to connect database in Selenium:
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)”, “”);
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();
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)
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();
Below code is used to write Selenium WebDriver test using command line:
java -classpath “.;selenium-server-standalone-2.33.0.jar” ExampleClass
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.
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.
INQUIRY
By tapping continuing, you agree to our Privacy Policy and Terms & Conditions
SkillAhead Solutions
Gurgaon
USA
1603, Capitol Avenue, Suite 413A, 2659, Cheyenne, WY 82001, USA
`Copyright © DevLabs Alliance. All rights Reserved`
|
Refund & Reschedule Policy
Privacy Policy
Terms of Use