Found 871 Articles for Automation Testing

How to upload file with selenium (Python)?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:23:02

13K+ Views

We can upload files with Selenium using Python. This can be done with the help of the send_keys method. First, we shall identify the element which does the task of selecting the file path that has to be uploaded.This feature is only applied to elements having the type attribute set to file. Also, the tagname of the element should be input. Let us investigate the html code of an element having the above properties.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.maximize_window() driver.get("https://www.tutorialspoint.com/selenium/selenium_automat ion_practice.htm") #to identify element s = driver.find_element_by_xpath("//input[@type='file']") #file path specified with send_keys s.send_keys("C:\Users\Pictures\Logo.jpg")OutputRead More

File Upload using Selenium WebDriver and Java Robot Class.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:20:53

6K+ Views

We can upload a file with Java Robot class in Selenium webdriver. It can produce simulationsfor the Keyboard and Mouse Event. It is derived from the AWT package.SyntaxRobot r = new Robot(); r.keyPress(KeyEvent.VK_ENTER); r.keyRelease(KeyEvent.VK_ENTER);ExampleCode Implementationimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import java.awt.*; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent; import org.openqa.selenium.JavascriptExecutor; public class RobotUplFile{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);       driver.get("http://my.monsterindia.com/create_account.html");       // scroll to reach upload button       JavascriptExecutor j = (JavascriptExecutor)driver; ... Read More

How to start selenium browser with proxy?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:18:44

851 Views

We can start Selenium browser with proxy. The proxy server is an important tool to perform testing on localization. We can take an e-commerce site and verify that the language and currency displayed is as per the location of the user.Using the proxy server within tests, we can test the look and feel of the site for a user belonging to a particular location. First of all, we have to configure an authenticated proxy server with below steps −Importing the webdriver from the Selenium package.Declare proxy server.Configure ChromeOptions classClubbing proxy server to the ChromeOptions.Pass options to Chrome() object.ExampleCode Implementation to ... Read More

Disable images in Selenium Google ChromeDriver.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:17:30

1K+ Views

We can disable images in Selenium in chromedriver. The images are sometimes disabled so that page load takes less time and execution is quick. In Chrome, we can do this with the help of the prefs setting.Syntaxprefs.put("profile.managed_default_content_settings.images", 2);Let’s us make an attempt to disable all image 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 ChromeDisableImg {    public static void main(String[] args) throws IOException {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       Map prefs = new HashMap();       // browser setting to disable image       prefs.put("profile.managed_default_content_settings.images", 2); ... Read More

How to save a canvas as PNG in Selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:15:03

1K+ Views

We can save a canvas as png in Selenium. We shall first identify the canvas with the help of any locators like xpath, css, and so on. Then obtain the value of src attribute with the getAttribute method.We shall build an URL in java with the class URL and have a BufferedImage via ImageIOclass. Then utilize the same class to save the canvas with the png extension in a location.Let us try to save the below image within the project folder.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; import javax.imageio.ImageIO; public class SaveCanvas{    public static void main(String[] args) { ... Read More

How to get an attribute value from a href link in selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:12:48

11K+ Views

We can get an attribute value from a href link in Selenium. To begin with, we have to first identify the element having an anchor tag with the help of any of the locators like css, id, class, and so on.Next, we shall use the getAttribute method and pass href as a parameter to the method. Let us investigate an element with an anchor tag having the href attribute. Here, the value of href should contain /about/about_team.htm.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 HrefValue{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); ... Read More

Human-like mouse movements with Selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:10:18

2K+ Views

We can do human-like mouse movements with Selenium. This can be done with the help of the Actions class. The human-like mouse movements include right-click, double-click, mouse movement, drag and drop, and so on.To do the mouse movement, the moveToElement method is used. To perform a right-click, the contextClick method is used. Finally, to actually execute the actions, build and perform methods should be added.Once we right-click on an element, various options get displayed. We have to add the import org.openqa.selenium.interactions.Actions package for implementing Actions.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; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; public class RightClick{    public static void ... Read More

Selenium and Headless Environment.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:07:47

831 Views

We can execute Selenium in a headless environment. The headless execution is a new trend followed in industry today since it is fast and supports more than one browser.Firefox in headless mode, can be run once we configure the geckodriver path. We shall then use the FirefoxOptions class, and send the headless knowledge to the browser with setHeadless method and pass true as a parameter to it.SyntaxFirefoxOptions o = new FirefoxOptions(); o.setHeadless(true); WebDriver driver = new FirefoxDriver(o);ExampleCode Implementation.import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import java.util.concurrent.TimeUnit; public class HeadlessFirefox{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");     ... Read More

Downloading with chrome headless and selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:05:46

658 Views

We can download Chrome in headless mode in Selenium. The headless execution is one of the ways saving resources by not utilizing the complete graphical interface.After the version 59, Chrome can be used in headless mode. The ChromeOptions class is used to modify the default character of the browser. The parameter headless is passed as a parameter to the addArgument method for headless execution.SyntaxChromeOptions o = new ChromeOptions(); o.addArguments("headless"); WebDriver driver = new ChromeDriver(o);ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class HeadlessChrome{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");     ... Read More

Does Selenium support headless browser testing?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:03:36

252 Views

Yes, Selenium supports headless browser testing. This can be done with the help of the HTMLUnitDriver. It is the fastest webdriver among other browser drivers and is platform independent.After Selenium 2.53 version, HTMLUnitDriver jar has to be added explicitly within the project. To add the dependency, follow the steps as listed below −Navigate to the link − https://github.com/SeleniumHQ/htmlunitdriver/releases.Click on the link highlighted in the below image.Right-click on the project and choose Build path. Then click on Configure Build Path.Go to Java Build Path, then select Libraries. Click on Add External JARs. Then browse and add the HTMLUnitDriver jar.We have to add ... Read More

Advertisements