Avoid Pop-Up Window in Chrome Browser with Selenium

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:30:50

3K+ Views

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 More

Delete an Element in Selenium Using Python

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:30:25

8K+ Views

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 More

Overwrite Field Value Using SendKeys in Selenium WebDriver with Java

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:29:51

2K+ Views

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 More

Launch Edge Browser with Selenium WebDriver

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:29:11

8K+ Views

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 More

Handle Multiple Keyboard Keys Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:21:31

2K+ Views

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 More

Open New Tab in Same Browser and Switch Using Selenium

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:17:45

7K+ Views

We can open new tabs in the same browser and switch between them using Selenium webdriver. Firstly, to open a new tab in the same browser we have to take the help of the methods – Keys.chord and sendKeys.The parameters Keys.CONTROL and Keys.ENTER are passed to the Keys.chord method. This method yields a string value and in turn passed as a parameter to the sendKeys method.SyntaxString n = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.id("open-tab")).sendKeys(n);Once the second tab is opened, the getWindowHandles method is used to hold all the window handle ids in a Set. To shift the focus of the webdriver object to ... Read More

Scroll Up and Down a Page Using Actions Class in Selenium

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:14:47

11K+ Views

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 More

Open Browser Window in Full Screen Using Selenium WebDriver

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:13:21

2K+ Views

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

Select Item from Sub Menu Using Mouse Over Action in Selenium

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:09:29

7K+ Views

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 More

Length of Longest String Chain in JavaScript

AmitDiwan
Updated on 07-Apr-2021 08:03:09

399 Views

Word ChainLet's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2. For example, "abc" is a predecessor of "abac".A word chain is a sequence of words [word_1, word_2, ..., word_k] with k >= 1, where word_1 is a predecessor of word_2, word_2 is a predecessor of word_3, and so on.ProblemWe are required to write a JavaScript function that takes in an array of strings, arr, as the first and the only argument.Each string in the array arr consists of English lowercase letters. Our ... Read More

Advertisements