We can click a link in Selenium by the following locators along with click() method.By link text.By partial link text.Code Implementation with link text locator.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 LinkScripting { 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(10, TimeUnit.SECONDS); driver.findElement(By.linkText("Coding Ground")).click(); driver.close(); } }Code Implementation with partial link text locator.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; ... Read More
Suppose we have two binary trees; we have to define a function to check whether they are the same or not. We know that the binary trees are considered the same when they are structurally identical and the nodes have the same value.So, if the input is like [1, 2, 3], [1, 2, 3], then the output will be TrueTo solve this, we will follow these steps −Define a function called isSameTree, this will take two tree nodes p and qif p is the same as NULL and q is same as NULL, then −return trueif p is the same ... Read More
We can enter text in the edit box in Selenium by the following ways −By invoking sendkeys() method.Using the class JavascriptExecutor.Code Implementation with sendkeys() 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 TextEnter { 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); driver.findElement(By.className("gsc-input")) .sendKeys("Selenium"); driver.close(); } }Code Implementation with class JavascriptExecutor method.Exampleimport org.openqa.selenium.By; ... Read More
Suppose we have a sorted linked list; we have to delete all duplicates such that each element appears only once.So, if the input is like [1, 1, 2, 3, 3, 3, 4, 5, 5], then the output will be [1, 2, 3, 4, 5]To solve this, we will follow these steps −dummy := make a new node with value -infnext of dummy := headcurr = dummywhile curr is non-zero, do −next = next of currwhile (next is not null and val of next is same as val of curr), do −next := next of nextnext of curr := nextcurr := ... Read More
Suppose we have a string s. s can hold any English letters and white-spaces. We have to find the length of last word in the string. If there is no last word, then return 0.So, if the input is like "I love Programming", then the output will be 11To solve this, we will follow these steps −n := 0for each word temp in a string −n := size of tempreturn nExampleLet us see the following implementation to get a better understanding − Live Demo#include using namespace std; class Solution { public: int lengthOfLastWord(string s){ stringstream str(s); ... Read More
The most basic steps to write a web driver script are listed below −Open any browser by creating a webdriver reference pointing to the corresponding browser driver class.Launch any URL with the get() method.Pause for some time for the page load.Confirm that we are on the correct web page.Finally close the session.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; public class WebScripting { 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"; ... Read More
Suppose we have a sorted array arr and a target value, we have to find the index when the target is found. If that is not present, then return the index where it would be if it were inserted in order.So, if the input is like [1, 3, 4, 6, 6], and target = 5, then the output will be 3, as we can insert 5 at index 3, so the array will be [1, 3, 4, 5, 6, 6]To solve this, we will follow these steps−n := size of Aif n < 1, then −return 0low := 0, high ... Read More
Selenium IDE by default has a language system commonly called Selenese. It is a group of commands used to perform operations on the web. It primarily helps to develop scripts in Selenium IDE.It can verify if an element is present on a screen, alerts, Ajax calls, links and many more. There are three types of commands used in Selenese. They are as the following −Actions − These are the commands which can change the condition of an application. For example, clicking a checkbox, submitting a form, selecting an option from dropdown. In case the action is not performed on the ... Read More
Suppose we have an array num and another value val, we have to remove all instances of that value in-place and find the new length.So, if the input is like [0, 1, 5, 5, 3, 0, 4, 5] 5, then the output will be 5.To solve this, we will follow these steps −count := 0for each index i of numsif nums[i] is not equal to val, then −nums[count] := nums[i]count := count + 1return countExampleLet us see the following implementation to get a better understanding − Live Democlass Solution: def removeElement(self, nums, val): count = 0 ... Read More
The name of the web drivers supported by Selenium are listed below −Google Chrome Driver [ ChromeDriver() supports chrome ]HTML Unit Driver [ WebClient() supports chrome, firefox and IE ]Safari Driver [ SafariDriver() supports Safari ]IOS Driver [ IOSDriver() supports ios ]Android Driver [ AndroidDriver() supports Android ]OperaChromium Driver [ ChromeDriver() supports opera ]Gecko Driver [ FirefoxDriver() supports firefox ]Microsoft WebDriver [ InternetExplorerDriver() supports IE ]EventFiring WebDriver [ EventFiring Driver() supports majority of browsers ]Code Implementation with Firefox driverExampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class BrowserDriverScript { public static void main(String[] args) ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP