Found 871 Articles for Automation Testing

Does Selenium support Safari browser?

Debomita Bhattacharjee
Updated on 02-Feb-2021 11:35:32

823 Views

Yes Selenium webdriver supports Safari browser. Safari is a prominent browser and is provided by default by Apple devices. For Safari versions 10 and greater than 10, the safaridriver comes automatically and is not required to be installed separately.The location of the SafariDriver is: /usr/bin/safaridriver. Also, it must be remembered that to work with the Safari latest version, users should have the Apple machine. This is because the Apply no longer supports Safari on Windows (from 2012).If we are using an older version of Safari in the Apple machine, we have to turn on the webdriver support, by running the ... Read More

Finding text on page with Selenium 2

Debomita Bhattacharjee
Updated on 02-Feb-2021 11:35:54

584 Views

We can find text on page with Selenium webdriver. First of all, we shall identify the element with the help of the locator xpath. In xpath, we can use the contains() and text() functions.Let us find the below highlighted text on the page −The xpath expression shall be //*[contains(text(), 'You are browsing')]. To obtain the text of the element, the getText method is used. Let us check the xpath expression we have created from the Console tab with the expression: $x("//*[contains(text(), 'You are browsing')]").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 FindElmntsText{    public static void ... Read More

How to change user agent for Selenium driver?

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

12K+ Views

We can change the user Agent for Selenium webdriver. The user Agent header has a particular string that provides the network protocol along with the details of operating system, software version, application, and so on.Selenium does have the ability to get or modify user Agent. This is done with the help of the JavaScript Executor. Selenium executes JavaScript commands with the help of the execute_script method.To obtain the user Agent information, we have to pass the return navigator.userAgent parameter to that method. To change the user Agent, we shall take the help of ChromeOptions class.Then apply the add_argument method on ... Read More

How to get userAgent information in Selenium Web driver?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:42:59

4K+ Views

We can get the user Agent information with Selenium webdriver. This is done with the help of the JavaScript Executor. Selenium executes JavaScript commands with the help of the execute_script method.To obtain the user Agent information, we have to pass the return navigator.userAgent parameter to the execute_script method. Selenium does have a direct method the to get or modify user Agent.Syntaxa= driver.execute_script("return navigator.userAgent") print(a)Examplefrom selenium import webdriver from selenium.webdriver.chrome.options import Options #object of Options class op = webdriver.ChromeOptions() #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/"); #get user Agent with execute_script a= driver.execute_script("return navigator.userAgent") print("User ... Read More

Set up a real timeout for loading page in Selenium WebDriver?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:42:10

4K+ Views

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 More

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

Advertisements