Found 519 Articles for Selenium

How to connect to Chromium Headless using Selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:21:59

346 Views

We can connect to Chromium headless with Selenium. The headless execution helps in reducing resource utilization and is a modern technique used in the industry.Chrome can be used in headless mode after the 59 version. The ChromeOptions class is used to change the default browser behavior. The headless value is passed to the addArguments method as a parameter for headless execution.SyntaxChromeOptions op = new ChromeOptions(); op.addArguments("headless"); WebDriver d = new ChromeDriver(op);ExampleCode Implementation.import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class HeadlessChromium{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       //ChromeOptions object     ... Read More

How to get HTTP Response Code using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:16:29

4K+ Views

We can get an HTTP response code in Selenium webdriver. While running test cases, we can check the response code from a resource. Common HTTP response codes include −5XX – Issue in server.4XX – Resource cannot be determined.3XX - Redirection.2XX – Fine.An object of the class HttpURLConnection is created to get the HTTP response code. To establish a link to an URL, the openConnection method shall be used. Next, we shall utilize the setRequestMethod and pass HEAD as a parameter.For connection, the connect method is to be applied to the instance of the HttpURLConnection class. At last, the getResponseCode method ... Read More

How to Disable images in Selenium Google ChromeDriver?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:13:43

564 Views

We can disable images in Selenium Google chromedriver. The images are disabled so that page load is quicker and execution time is also less. In chromedriver, we have to configure the below browser parameter −profile.managed_default_content_settings.images, and set its value to 2.Syntaxp.put("profile.managed_default_content_settings.images", 2);Let’s try to disable images from the below page −ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.HashMap; import java.util.Map; public class ImageDisable {    public static void main(String[] args) throws IOException {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       Map p = new HashMap();       // browser setting to disable image       p.put("profile.managed_default_content_settings.images", ... Read More

Running Selenium Webdriver with a proxy in Python.

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:07:38

4K+ Views

We can run a proxy with Selenium webdriver in Python. A proxy is an essential component to do localization testing. We can take an e-commerce application and check if the language and currency visible is as per the user location.With the help of proxy within tests, we can verify if the website user interface matches with the location. We have to SET a proxy with below steps −Import webdriver from Selenium package.Define proxy server address.Create an object of ChromeOptions classCommunication of proxy with ChromeOptions.Summing options to Chrome() object.ExampleCode Implementation.from selenium import webdriver #proxy server definition py = "128.21.0.0:8080" #configure ChromeOptions ... Read More

Clicking on elements within an SVG using XPath (Selenium WebDriver).

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:06:01

10K+ Views

We can click on elements with an SVG using XPath in Selenium. The SVG element has the tag name svg. It has attributes like width, height, viewBox, and so on.To click the element with svg, we should identify the element then utilize the Actions class. We shall first move to that element with the moveToElement method and then apply the click method on it.Finally, to actually perform the action, we have to use the build and execute methods. To identify the svg element with xpath, there is the local-name() function available.Let us look at the html code of a svg ... Read More

How to hide Firefox window (Selenium WebDriver)?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:03:19

1K+ Views

We can hide the Firefox window in Selenium webdriver. This can be done by making the browser headless. We shall achieve this with the FirefoxOptions class. We shall then create an object option of that class.We have to make the browser setting options.headless to True value. This driver object shall then receive this information. We need to have the import statement: from selenium.webdriver.firefox.options import Options as FirefoxOptions for adding the FirefoxOptions class.Syntaxoptions = webdriver.FirefoxOptions() options.headless = TrueExampleCode Implementation.from selenium import webdriver from selenium.webdriver.firefox.options import Options as FirefoxOptions #object of FirefoxOptions options = webdriver.FirefoxOptions() #setting headless parameter options.headless = True driver ... Read More

How to upload a file in Selenium with no text box?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:01:34

2K+ Views

We can upload a file in Selenium with no text box. This is achieved with the help of the sendKeys method. It is applied on the web element which performs the task of selecting the path of the file to be uploaded.As we make an attempt to upload, we shall click on the Browse button. If we investigate the HTML code for this, we shall be able to locate the attribute type having the value file. Moreover, the file path to be uploaded should be accurate.ExampleCode Implementation.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 FileUpload{   ... Read More

How to simulate pressing enter in html text input with Selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:33:51

559 Views

We can simulate pressing enter in the html text input box with Selenium webdriver. We shall take the help of sendKeys method and pass Keys.ENTER as an argument to the method. Besides, we can pass Keys.RETURN as an argument to the method to perform the same task.Also, we have to import org.openqa.selenium.Keys package to the code for using the Keys class. Let us press ENTER/RETURN after entering some text inside the below input box.ExampleCode Implementation with Keys.ENTER.import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.openqa.selenium.Keys; public class PressEnter{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", ... Read More

How do I change focus to a new popup tab in Selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:32:15

3K+ Views

We can change focus to a new popup tab with Selenium webdriver. The getWindowHandles and getWindowHandle methods are available to handle new popup tabs. The getWindowHandles method stores all the currently opened window handles in Set data structure.The getWindowHandle method stores the window handle of the opened browser in focus. The iterator method is used to iterate over all the window handle ids. We have to add import java.util.Set to accommodate Set and import java.util.List and import java.util.Iterator statements to accommodate the iterator in our code.Selenium driver object can access the elements of the parent window. In order to switch ... Read More

How to wait until an element no longer exists in Selenium?

Debomita Bhattacharjee
Updated on 26-Oct-2020 07:30:40

6K+ Views

We can wait until an element no longer exists in Selenium webdriver. This can be achieved with synchronization in Selenium. We shall add an explicit wait criteria where we shall stop or wait till the element no longer exists.Timeout exception is thrown once the explicit wait time has elapsed and the expected behavior of the element is still not available on the page. To check if an element no longer exists on the page, we can take the help of the expected condition invisibilityOfElementLocated.To implement explicit wait conditions, we have to take help of the WebDriverWait and ExpectedCondition class.ExampleCode Implementation.import ... Read More

Advertisements