Found 871 Articles for Automation Testing

Selenium testing without browser.

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

6K+ Views

We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.For triggering headless execution in Chrome, the ChromeOptions class is utilized to modify the default browser characteristics. Headless is passed as a parameter to the addArguments.SyntaxChromeOptions opt = new ChromeOptions(); opt.addArguments("headless"); WebDriver d = new ChromeDriver(opt);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 WithoutBrowsr{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       //ChromeOptions object       ChromeOptions opt ... Read More

How do I pass options to the Selenium Chrome driver using Python?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:52:04

2K+ Views

We can pass options to the Selenium Chrome driver using Python. This can be with the help of the ChromeOptions and the DesiredCapabilities class. For the ChromeOptions, we have to create an object for that class.Then we shall take the help of the add_argument method and pass the option we want to send to the browser as a parameter to the method. Finally, this information must be given to the web driver.ExampleCode Implementation.from selenium import webdriver from selenium.webdriver.chrome.options import Options as ChromeOptions #object of ChromeOptions op = webdriver.ChromeOptions() #add option op.add_argument('--enable-extensions') #pass option to webdriver object driver = webdriver.Chrome(chrome_options=op)We can ... Read More

How to save and load cookies using Python Selenium WebDriver?

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

2K+ Views

We can save and load cookies with Selenium webdriver in Python. A cookie is an information saved by the browser about the application. A cookie is stored in a key value pair.It is generally used to hold the credentials of users. It also stores information about the user actions on the browser within the cookie file. We can add, obtain and delete cookies of the browser.Syntaxc = driver.get_cookies() ck = { 'name': 'Selenium', 'value': 'Java'} driver.add_cookie(ck)ExampleCode Implementationfrom selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.maximize_window() driver.get("https://www.tutorialspoint.com/index.htm") #get current cookies c = driver.get_cookies() print(c) #count cookies with len method print(len(c)) # ... Read More

How to send cookies with selenium webdriver?

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

585 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

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

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

Advertisements