Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Debomita Bhattacharjee
Page 27 of 59
Set up a real timeout for loading page in Selenium WebDriver?
We can set a real timeout for loading pages in Selenium webdriver. There are numerous methods to implement timeouts. They are listed below −setScriptTimeout.pageLoadTimeout.implicitlyWait.The setScriptTimeout is the method to set the time for the webdriver. This is usually applied for an asynchronous test to complete prior throwing an exception. The default value of timeout is 0.This method is generally used for JavaScript commands in Selenium. If we omit setting time for the script, the executeAsyncScript method can encounter failure due to the more time consumed by the JavaScript to complete execution.If the timeout time is set to negative, then the ...
Read MoreHow to get Selenium to wait for ajax response?
We can get Selenium to wait for Ajax response. The determination of the load time of the page due to an Ajax response is a difficult task. This can be achieved with the help of synchronization concepts and wait methods in Selenium are −Implicit wait − It allows the web driver to wait for the time specified after which exception is thrown. This wait is applicable to the all the steps in the test.Syntaxdriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);ExampleCode Implementation with implicit wait.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class AjaxImplWt{ public static void main(String[] args) { ...
Read MoreHow to disable Javascript when using Selenium?
We can disable JavaScript using Selenium webdriver. We have to use the Options class to achieve this task. Firstly, we have to create an object of the Options class.Then apply the set_preference method on that object. For disabling the JavaScript, we shall set the browser parameter javascript.enabled to False. Also this information should be passed to the driver object.Syntaxop = Options() op.set_preference('javascript.enabled', False)We can get the javascript.enabled parameter of the browser by following the below steps −Open a browser.Type about:config in browser address.Enter javascript in the search bar.Examplefrom selenium import webdriver from selenium.webdriver.firefox.options import Options #object of Options class op ...
Read MoreUnderstanding execute async script in Selenium
We can use the executeAsyncScript method in Selenium webdriver. For an executeAsyncScript method, JavaScript Executor runs an asynchronous part of JavaScript with the reference to the present selected window or frame. In contrast to executeScript, the scripts which run with executeAsyncScript method, should be completed by invoking the given callback.The callback is always added as the last argument within the executed function. The first argument passed is used to get the script result.If the script consists of a return statement, then the below rules are followed −A webelement is returned for an HTML element.A double is returned for a decimal ...
Read MoreCan Selenium be used for .NET applications?
We can use Selenium for .NET applications. We should have Visual Studio 2019 installed in the system along with Selenium webdriver and any browser like Firefox, Chrome, and so on. Then we must utilize the NUnit framework.Launch Visual Studio 2019 and then click on Create a new project.Type NUnit in the search box appearing in Create a new project pop−up. Select NUnit Test Project(.NET Core) from the search results.Enter Project name and Location. Then click on Create to proceed.As the project is set up on NUnit(.Net Core), the Setup and Test methods shall be given by default.We should navigate to ...
Read MoreHow to check if dom has a class using WebDriver (Selenium 2)?
We can check if DOM has a class using Selenium webdriver. We can use the findElements method to obtain the list of elements having a particular class. Then pass By.className or By.xpath or By.cssSelector as a parameter to the method.The class name we want to search is passed as a parameter to that method. Let us investigate the below html code for an ul element having class value as toc chapters. Then obtain its sub-elements.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class ClassAttrb{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", ...
Read MoreWebDriver executeAsyncScript vs executeScript in Selenium
There are differences between executeAsyncScript and executeScript methods. For an executeScript method, JavaScript Executor runs the JavaScript with the reference to the present selected window or frame. The script within the method shall run as the body of the unnamed function.Inside the script, the documents are used to point to the present document. Also, the local variables will not be present as the script has completed execution. However, the global variables shall be present.If the script consists of a return statement, then the below rules are followed −A webelement is returned for an HTML element.A double is returned for a ...
Read MoreHow do you make Selenium 2.0 wait for the page to load?
We can make Selenium wait for the page to load. We can use the synchronization concept in Selenium to wait for page loading. The implicit wait is a type of synchronization applied to elements to wait for a specified amount of time.Syntaxdriver.manage().timeouts().implicitlyWait();We can also call the JavaScript method document.readyState and wait till it yields the value complete. Selenium executes JavaScript command with the help of the executeScript method.SyntaxJavascriptExecutor j = (JavascriptExecutor)driver; j.executeScript("return document.readyState").toString().equals("complete");Post this step, we should check if the URL is similar to the one we are looking for.ExampleCode Implementation with implicit wait.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import ...
Read MoreHow do I verify that an element does not exist in Selenium 2?
We can verify if an element does not exist in Selenium webdriver. To achieve this, we shall use the method getPageSource which gets the entire page source. So we can obtain a complete page source and check if the text of the element exists.We also use the findElements method and utilize any locators like xpath, CSS, and so on to identify the matching elements. The findElements gives an elements list.We shall count the number of elements returned by the list with the help of the size method. If the value of size is greater than 0, then the element exists ...
Read MoreHow to integrate Sikuli scripts into Selenium?
We can integrate Sikuli scripts into Selenium webdriver. Sikuli is an automation tool which is open-source. It has the feature to capture the images on the elements as well as perform operations on them.Some of the advantages of Sikuli are −Desktop or Windows applications can be automated.Can be used for flash testing.Can be used on platforms like mobile, Mac, and Linux.It is based on image recognition technique.Can be easily integrated with Selenium.To integrate Sikuli with Selenium, follow the below steps − Navigate to the link − https://launchpad.net/sikuli/+download.Click on the jar to download it (which can be used for Java environments) ...
Read More