In this tutorial, we are going to write a program that computes the time taken for a signal to reach all positions in a string. Let me explain it with an example.We will have a string that contains only s and p characters. s is a signal and p is a position in the string. A signal starts at s and travels in both left and right directions. We are assuming it takes one unit of time to travel to the next position in the string. Our task is to compute the time needed to convert all positions into signals.Let's ... Read More
In this tutorial, we are going to write a program that is based on the concepts of LCM. As the title says, we have to find three numbers that are less than or equal to the given number whose LCM is maximum.Let's see an example.Before diving into the problem let's see what LCM is and write program for it.LCM is the least common multiple of a number. It is also known as Least common divisor. For two positive number a and b, the LCM is the smallest integer that is evenly divisible by both a and b.If the given integers ... Read More
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
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
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP