Found 519 Articles for Selenium

How to send cookies with selenium webdriver?

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

562 Views

We can send cookies with Selenium webdriver. A cookie is stored in a key value pair. First, we have to add cookies, then can delete them. We can also get the cookies.Also, we have to add import org.openqa.selenium.Cookie statement for cookie implementations.SyntaxCookie ck = new Cookie("Automation", "QA"); driver.manage().addCookie(ck); driver.manage().getCookies(); driver.manage().deleteAllCookies();ExampleCode Implementationimport java.util.Set; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.Cookie; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class CookiesSend{    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(4, TimeUnit.SECONDS);       driver.get("https://www.tutorialspoint.com/index.htm");       // cookie set ... Read More

Downloading file to specified location with Selenium and python.

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

6K+ Views

We can download files to a specified location with Selenium in Python. This is done by the help of the ChromeOptions class. We shall set the preferences of the browser and pass the download.default_directory parameter.We need to mention the path of the download directory with that parameter. This preference is sent to the ChromeOptions object with the add_experimental_option method.Finally, this browser information is shared with the driver object.Syntaxop = webdriver.ChromeOptions() p = ("download.default_directory": "C:\Users", "safebrowsing.enabled":"false") op.add_experimental_option("prefs", p) driver = webdriver.Chrome(chrome_options=op)ExampleCode Implementation.from selenium import webdriver from selenium.webdriver.common.by import By #object of ChromeOptions op = webdriver.ChromeOptions() #set download directory path p = ("download.default_directory": "C:\Users""safebrowsing.enabled":"false") ... Read More

How to click Allow on Show Notifications popup using Selenium Webdriver?

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

4K+ Views

We can click Allow on show notification pop-up in Selenium webdriver.These are messages from the website and often called as web push notification.This can be handled with the browser settings.This is done with the help of the ChromeOptions class. We shall create an object of it and apply the addArguments method on it. Then pass --disable-notifications as a parameter to the method.Finally, this information should be sent to the driver object.SyntaxChromeOptions p = new ChromeOptions(); p.addArguments("--disable-notifications");Let us try to handle the below notification on a page.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 BrowserNotification{    public static void main(String[] args) ... Read More

How to use xPath in Selenium WebDriver to grab SVG elements?

Debomita Bhattacharjee
Updated on 15-Sep-2023 01:19:53

29K+ Views

We can use xpath to grab SVG elements with Selenium Webdriver. A SVG element is identified with tagname svg. The svg image has the attributes like width and height attributes.Let us investigate the html code of a svg element.To create a xpath for a svg element, we have the syntax as //*[local-name()='svg'].The local-name function is mandatory for creating a xpath of a svg element. So for the xpath expression for the image highlighted in the above image should be −//*[local-name()='svg' and @data-icon='home']/*[local-name()='path']Here, data-icon is an attribute of the svg tag element which is added accompanied with @ symbol. The [local-name()='path'] is ... Read More

How to run selenium (Firefox) web driver without a GUI?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:29:01

1K+ Views

We can run Selenium (Firefox) webdriver without a GUI. This means that the execution has to be kicked in headless mode. The headless execution is popular now since it results in less consumption of resources.Firefox, without GUI, can be executed after we set the geckodriver path. We shall take the help of FirefoxOptions class, share this information to the browser via the setHeadless method. Finally pass true as a parameter to that.SyntaxFirefoxOptions op = new FirefoxOptions(); op.setHeadless(true); WebDriver driver = new FirefoxDriver(op);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 FirefoxNoGUI{    public static void main(String[] args) {       ... Read More

How to make firefox headless programmatically in Selenium with python?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:26:54

1K+ Views

We can make firefox headless programmatically in Selenium. This can be done with the help of the FirefoxOptions class. We shall then create an object option for that class.We shall set the parameter options.headless to True value. This information of the browser has to be passed to the driver object. We have to add the import statement: from selenium.webdriver.firefox.options import Options as FirefoxOptions for 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() #set options.headless to True options.headless = True driver = webdriver. Firefox(executable_path="C:\geckodriver.exe", options=options) driver.implicitly_wait(0.4) driver.get("https://www.tutorialspoint.com/index.htm") #identify ... Read More

How can I control Chromedriver open window size?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:25:14

2K+ 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
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

828 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

Advertisements