Selenium Articles

Page 25 of 37

How can I control Chromedriver open window size?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 3K+ Views

We can control the chromedriver to open with a window size in Selenium. This is done with the help of ChromeOptions class. We have to create an object of that and apply addArguments method on it.Then pass window-size=x, y as a parameter to the method. The x and y are the dimensions of the window. Next, we have to apply this option to the Chrome browser with the DesiredCapabilities class. Finally, this information is sent to the driver object.SyntaxChromeOptions op = new ChromeOptions(); op.addArguments("window-size=500, 250"); DesiredCapabilities c = DesiredCapabilities.chrome(); c.setCapability(ChromeOptions.CAPABILITY, op); WebDriver d = new ChromeDriver(op);ExampleCode Implementation.import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.chrome.ChromeDriver; import ...

Read More

How to upload file with selenium (Python)?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 15K+ 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")Output

Read More

File Upload using Selenium WebDriver and Java Robot Class.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 8K+ 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 save a canvas as PNG in Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 2K+ 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
Debomita Bhattacharjee
Updated on 28-Dec-2020 14K+ 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
Debomita Bhattacharjee
Updated on 28-Dec-2020 3K+ 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

Downloading with chrome headless and selenium.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 844 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

Access to file download dialog in Firefox in Selenium.

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 739 Views

We can access file download dialog in Firefox in Selenium. For this we have to first modify the default directory where the downloaded file gets stored. This is done by the addpreference method.p.addPreference("browser.download.folderList", 2);Then, define the new path of the download directory.Finally, we shall ignore the save to disk and open file options in dialog for the file types via their MIME code. The addPreference method can be called with the help of FirefoxOptions class.ExampleCode Implementation.import org.openqa.selenium.By; 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 FileDwnloadWithoutDialg{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); ...

Read More

How to set default download directory in selenium Chrome Capabilities?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 4K+ Views

We can set the default download directory in Selenium with Chrome capabilities. All the browsers have a download directory set by default. We can modify it via the browser settings.We can change the setting manually, but it gets modified on triggering a script. We change the directory for download in Chrome browser with the help of ChromeOptions class.We are required to add capabilities to the browser with the parameter download.default_directory. The path of the new location to be set is considered as its value.ExampleCode Implementation.import java.io.File; import org.openqa.selenium.By; import java.io.IOException; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.HashMap; import java.util.Map; public class SetDownloadPathChrome ...

Read More

How can I download a file on a click event using selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 28-Dec-2020 2K+ Views

We can download a file on a click event in Selenium. Normally, on clicking on the download link, a pop-up comes with the file name along with the Open and Save option.To download with a click event, an object of the FirefoxOptions class is to be created. Then with the addPreference method, we shall configure browser preferences.We shall mention the location where the download is to be done along with the neverAsk.openFile and neverAsk.saveToDisk preferences are to be set.ExampleCode Implementation.import org.openqa.selenium.By; 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 FileDwnloadWithClick{    public static void main(String[] args) {   ...

Read More
Showing 241–250 of 362 articles
« Prev 1 23 24 25 26 27 37 Next »
Advertisements