Found 719 Articles for Testing Tools

Using Extensions with Selenium & Python

Debomita Bhattacharjee
Updated on 02-Feb-2021 11:42:57

9K+ Views

We can use extensions with Selenium webdriver in Python. We can have multiple extensions of the Chrome browser while we manually open the browser and work on it.However, while the Chrome browser is opened through Selenium webdriver, those extensions which are available to the local browser will not be present. To configure an extension, we have to obtain the .crx extension file of the extension.Then we have to perform installation of the extension to the browser which is launched by Selenium. To get all the extensions available to the browser enter chrome://extensions on the browser address bar.To get add an ... Read More

Set Chrome's language using Selenium ChromeDriver

Debomita Bhattacharjee
Updated on 02-Feb-2021 11:38:58

5K+ Views

We can set Chrome browser language using Selenium webdriver. Some applications are designed such that it can be redesigned to multiple languages without any modifications. This is known as internationalization.In Selenium, we can modify the language preferences with the help of ChromeOptions class for the Chrome browser. We shall create an object of this class and apply addArguments method on it.To modify the language to Spanish, we have to pass −−lang=es as a parameter to the addArguments method. This information is then made available to the webdriver object.SyntaxChromeOptions opt = new ChromeOptions(); opt.addArguments("−−lang=es"); WebDriver drv = new ChromeDriver(opt);Exampleimport org.openqa.selenium.WebDriver; import ... Read More

How to fire javascript event in Selenium?

Debomita Bhattacharjee
Updated on 02-Feb-2021 11:37:50

1K+ Views

We can fire JavaScript events in Selenium webdriver. Selenium can execute JavaScript events with the help of the JavaScript Executor. We shall pass the JavaScript commands as a parameter to the executeScript method.We shall fire the JavaScript event of clicking an element. First of all, we shall identify the element with the help of any of the locators like xpath, css, link text, and so on.We shall then pass argument [0].click() and webelement that shall be clicked as parameters to the executeScript method.SyntaxWebElement m = driver.findElement(By.linkText("Write for us")); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].click();", m);Let us make try to click ... Read More

How to send keyboard shortcut ALT SHIFT z (hotkey) with Selenium2?

Debomita Bhattacharjee
Updated on 02-Feb-2021 11:36:05

2K+ Views

We can send keyboard shortcut ALT SHIFT z(hotkey) with Selenium webdriver. This can be done with the help of the Keys class. We shall use the Keys.chord method and pass Keys.ALT, Keys.SHIFT and z as parameters to that method.The entire value obtained from the Keys.chord method is obtained as a String. That is then sent as a parameter to the sendKeys method.SyntaxString s = Keys.chord(Keys.ALT, Keys.SHIFT, "z"); driver.findElement(By.tagName("html")).sendKeys(s);ExampleCode Implementation with Keys.chord method.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.Keys; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class HtKeys{    public static void main(String[] args) {          System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       ... Read More

How do I send a DELETE keystroke to a text field using Selenium with Python?

Debomita Bhattacharjee
Updated on 02-Feb-2021 11:39:27

6K+ Views

We can send a DELETE keystroke to a text field using Selenium webdriver with Python. First of all, we have to identify the text field with the help of any locators like xpath, css, id, and so on.We can enter a text in the text field with the send_keys method. The value to be entered is passed as parameter to the method. To delete a key, we can pass Keys.BACKSPACE as a parameter to the send_keys method.Syntaxl = driver.find_element_by_id("gsc−i−id1") l.send_keys("Sel") l.send_keys(Keys.BACKSPACE)To delete all the keys entered simultaneously, we have to pass CTRL+A and BACKSPACE as parameters to the send_keys method.Syntaxl ... Read More

Does Selenium support Safari browser?

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

826 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

591 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

Advertisements