Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Debomita Bhattacharjee
Page 18 of 59
How to avoid the pop-up window in chrome browser with Selenium?
We can avoid the pop-up window in Chrome browser with Selenium webdriver using the ChromeOptions class. We have to create an object of this class and apply the setExperimentalOption method to it. We shall create a Map and insert the below Chrome browser preference to it −profile.default_content_setting_values.notifications, and set its value to 2.The above browser preference shall be passed as a parameter to the method setExperimentalOption and finally added to the webdriver object.SyntaxMap pf = new HashMap(); pf.put("profile.default_content_setting_values.notifications", 2); ChromeOptions p = new ChromeOptions(); p.setExperimentalOption("prefs", pf);Exampleimport org.openqa.selenium.By; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.HashMap; import java.util.Map; import org.openqa.selenium.WebDriver; public class PopupDisable ...
Read MoreHow can I delete an element in Selenium using Python?
We can delete an element in Selenium webdriver using Python with the help of JavaScript Executor. Selenium is not capable of modifying the structure of DOM directly.It has the feature of injecting JavaScript into the webpage and changing the DOM with the help execute_script method. The JavaScript command to be used is passed as a parameter to this method.JavaScript command to delete an element is −var l = document.getElementsByClassName("tp-logo")[0]; l.parentNode.removeChild(l);The above script is to be passed as a parameter to the execute_script method.Let us try to remove the highlighted logo from the below page −Examplefrom selenium import webdriver #set chromodriver.exe ...
Read MoreSelenium WebDriver: I want to overwrite value in field instead of appending to it with sendKeys using Java
We can overwrite the value in the field instead of appending to it with sendKeys in Selenium webdriver. This can be done by using the Keys.chord method.It returns a string and can be applied to any web element with the help of the sendKeys method.To overwrite a value, we shall first select it with CTRL+A keys and then pass the new value. Thus, Keys.CONTROL, A and the new value are passed as parameters to the Keys.chord method.SyntaxString n = Keys.chord(Keys.CONTROL, "A"); WebElement l = driver.findElement(By.name("q")); l.sendKeys(n, "Tutorialspoint");Exampleimport 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.Keys; public class ...
Read MoreHow to launch Edge browser with Selenium Webdriver?
We can launch Edge browser with Selenium webdriver by using the Microsoft webdriver. We should also ensure that we are having the machine with the Windows 10 operating system.Navigate to the below link to download the Microsoft Edge driver executable file − https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/Once the page is launched, scroll down to the Downloads section, then choose and click the link which is compatible with our local Edge browser version.A zip file gets created, once the download is completed successfully. We have to then unzip the file and save it in a desired location. Then, set the path of the msedgedriver.exe file. ...
Read MoreHow can I handle multiple keyboard keys using Selenium Webdriver?
We can handle multiple keyboard keys in Selenium webdriver by using the method Keys.chord. The multiple keyboard keys to be handled are passed as parameters to this method.The return type of the Keys.chord method is a string and can be applied to an element with the help of the sendKeys method. For example, in order to perform a select operation on text entered inside an edit box we require the keys ctrl+a to be pressed simultaneously.SyntaxString k = Keys.chord(Keys.CONTROL, "A"); driver.findElement(By.name("q")).sendKeys(k);Exampleimport 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.Keys; public class MultipleKeys{ public static void main(String[] ...
Read MoreHow to scroll up/down a page using Actions class in Selenium?
We can perform scroll up/down a page using Actions class in Selenium webdriver. First of all, we have to create an object of this Actions class and then apply the sendKeys method on it.Now, to scroll down a page, we have to pass the parameter Keys.PAGE_DOWN to this method. To again scroll up a page, we have to pass the parameter Keys.PAGE_UP to the sendKeys method. Finally, we have to use the build and perform methods to actually perform this action.SyntaxActions a = new Actions(driver); //scroll down a page a.sendKeys(Keys.PAGE_DOWN).build().perform(); //scroll up a page a.sendKeys(Keys.PAGE_UP).build().perform();Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ...
Read MoreHow to open a browser window in full screen using Selenium WebDriver with C#?
We can open a browser window in full screen using Selenium webdriver in C# by using the method Maximize. This method has to be applied on the webdriver object.Syntaxdriver.Manage().Window.Maximize();Exampleusing NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; namespace NUnitTestProject1{ public class Tests{ String url = "https://www.google.com/"; IWebDriver driver; [SetUp] public void Setup(){ //object of FirefoxDriver driver = new FirefoxDriver(); } [Test] public void Test1(){ //URL launch driver.Navigate().GoToUrl(url); //browser maximize driver.Manage().Window.Maximize(); Console.WriteLine("Browser Maximized"); } [TearDown] public void closeBrowser(){ driver.Quit(); } } }Output
Read MoreSelect item from sub-menu of a menu using mouse over action in Selenium
We can select an item from the sub-menu of a menu using mouse over action in Selenium webdriver with the help of the Actions class. We shall create an object of the Actions class and then apply moveToElement to it.This method shall move the mouse to the middle of the menu which displays submenu on mouse over. Then apply the perform method to actually perform this action. After hovering on the menu, we shall select a sub-menu with the help of the click method.SyntaxWebElement n=driver.findElement(By.id("nav-link-accountList")); Actions a = new Actions(driver); a.moveToElement(n).perform();Let us hover on the below highlighted menu on the ...
Read MoreAlternative of click() in Selenium
There are several alternatives to the usage of click method in Selenium webdriver. We can use the JavaScript Executor to perform a click action. Selenium can execute JavaScript commands with the help of the executeScript method.The parameters – arguments[0].click() and locator of the element on which the click is to be performed are passed to this method.SyntaxWebElement n=driver.findElement(By.linkText("Refund")); JavascriptExecutor j = (JavascriptExecutor) driver; j.executeScript("arguments[0].click();", n);Exampleimport 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.JavascriptExecutor; public class JsClickLink{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); ...
Read MoreGoogle Search Automation with Python Selenium
We can perform Google search automation with Selenium webdriver in Python. First of all, we shall locate the Google search box with the help of any of the locators like id, css, xpath, class, or name.Then simulate the action of pressing the ENTER key with the help of Keys.ENTER/Keys.RETURN. To perform this operation, we have to use the method send_keys and then pass the parameter – Keys.RETURN /Keys.ENTER. Also, we have to add the statement - from selenium.webdriver.common.keys import Keys to use the Keys class.Examplefrom selenium import webdriver from selenium.webdriver.common.keys import Keys import time #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") ...
Read More