Suppose we have an array and an integer k, we have to check whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.So, if the input is like [1, 2, 4, 1] and k = 3, then the output will be TrueTo solve this, we will follow these steps −Define an array nn of pairsfor initialize i := 0, when i − size of nums, update (increase i by 1), do −insert {nums[i], i} at the end of nnsort the array ... Read More
The different cookies method in Selenium are listed below −driver.manage().deleteAllCookies() − This removes all cookies.driver.manage().deleteCookie(Id) − This removes a particular cookie.driver.manage().deleteCookieNamed(CookieName) − This removes a particular cookie based on Name.driver.manage().getCookies() − This returns all the cookies.driver.manage().getCookieNamed(CookieName) − This returns a particular cookie based on Name.driver.manage().addCookie(Id) − This adds a particular cookie.Code Implementation with some cookies method.Exampleimport org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class CookiesScripting { public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); // ... Read More
Suppose we have two strings s and t; we have to check whether they are isomorphic or not. Two strings are said to be isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.So, if the input is like s = "egg", t = "add”, then the output will be true, as e can map to a, and g can map to d.To solve this, we ... Read More
We can maximize the browser in Selenium with the help of method maximize().The present active window becomes maximized with this method.Code implementation.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class BrowserMax { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); // maximizing browser with maximize() driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.findElement(By.partialLinkText("Coding")).click(); driver.close(); } }Read More
Suppose we have a positive integer; we have to find its corresponding column title as appear in an Excel sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.So, if the input is like 28, then the output will be AB.To solve this, we will follow these steps −while n is non-zero, do −n := n - 1res := res + n mod 26 + ASCII of 'A'n := n / 26reverse the array resreturn resExample Let us see the following implementation to get a better understanding − Live Demo#include using namespace std; ... Read More
getWindowHandle() and getWindowHandles() methods have some prominent differences.driver.getWindowHandles() – It stores the set of handles for all the pages opened simultaneously.driver.getWindowHandle() – It fetches the handle of the web page which is in focus. It gets the address of the active browser and it has a return type of String.Code ImplementationExampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.Set; import java.util.Iterator; import org.testng.annotations.Test; public class WindowHandles{ @Test public void windowHandle() throws Exception { System.setProperty("webdriver.chrome.driver", "C:\Selenium\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); ... Read More
Suppose we have a non-negative index k where k ≤ 33, we have to find the kth index row of Pascal's triangle.So, if the input is like 3, then the output will be [1,3,3,1]To solve this, we will follow these steps −Define an array pascal of size rowIndex + 1 and fill this with 0for initialize r := 0, when r
We can get the value of the edit box in Selenium by the following ways −By using getText () method.Using the class JavascriptExecutor.Code Implementation with method getText ().Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class GetValueScripting { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); String text = driver.findElement(By.className("gsc-input")).getText(); System.out.println("Extracted text is " + text); driver.close(); ... Read More
Suppose we have a binary tree; we have to find the minimum depth of that tree. As we know the minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.So, if the input is likethen the output will be 2To solve this, we will follow these steps −Define an array aa of tree nodesinsert root at the end of aaDefine another array ak of tree nodeslevel := 0if root is null, then −return 0while size of aa is not equal to 0, do −clear the array ak(increase level by ... Read More
We can submit a form in Selenium by the following methods −submit()click()Code Implementation with submit() method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class SubmitScripting { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = ""; driver.get(url); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // submit method to submit the form driver.findElement(By.id("")).submit(); driver.close(); } }Code Implementation with method click().Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP