Found 719 Articles for Testing Tools

How to use chrome webdriver in Selenium to download files in Python?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:41:55

1K+ Views

We can use chrome webdriver in Selenium to download files in Python. We shall use the ChromeOptions class for this purpose. First, we shall create an object of the ChromeOptions class.Then apply the add_experimental_option method on the object created. We shall set the download.default_directory: parameter. Finally, this information shall be passed to the driver object.Syntaxop = webdriver.ChromeOptions() p = {'download.default_directory':'C:\Users\ghs6kor\Downloads\Test'} op.add_experimental_option('prefs', p)Examplefrom selenium import webdriver from selenium.webdriver.chrome.options import Options #object of Options class op = webdriver.ChromeOptions() #browser preferences p = {'download.default_directory':'C:\Users\ghs6kor\Downloads\Test'} #add options to browser op.add_experimental_option('prefs', p) #set chromedriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", options=op) #maximize browser driver.maximize_window() #launch URL driver.get("https://www.seleniumhq.org/download/"); #click ... Read More

How to get Selenium to wait for ajax response?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:37:47

3K+ Views

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 More

How to disable Javascript when using Selenium?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:34:27

3K+ Views

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 More

Understanding execute async script in Selenium

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:33:22

2K+ Views

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 More

Can Selenium be used for .NET applications?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:32:50

3K+ Views

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 More

How to check if dom has a class using WebDriver (Selenium 2)?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:26:58

298 Views

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 More

What is the best way to take screenshots of tests in Selenium 2?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:25:40

96 Views

We can take screenshots of tests in Selenium webdriver. Capturing a screenshot is one of the most essential steps in failure analysis of failed tests. It is a three way step process to take screenshots.Firstly, we shall convert the webdriver object to the interface called the TakeScreenshot. Then we have to utilize the getScreenshotAs method to capture the image. The file format of the image to be captured is passed as parameter to that method.Finally, the file where the image is captured is to be copied to a location with the FileUtils.copyFile method.SyntaxFile s = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(s, new File("Image.png"));Exampleimport org.openqa.selenium.By; ... Read More

WebDriver executeAsyncScript vs executeScript in Selenium

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:26:16

2K+ Views

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 More

How do you make Selenium 2.0 wait for the page to load?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:25:54

461 Views

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 More

How do I verify that an element does not exist in Selenium 2?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:19:14

6K+ Views

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 More

Advertisements