We can upload files to the browser with the help of Selenium webdriver. This is done with the help of sendKeys() method on the element which does the selection of the file by specifying the path of the file to be uploaded.While working on file upload functionality, we need to click on the Browse button. This is taken care of by webdriver for elements with attribute type having value as file. Also, the path of the file to be uploaded should be correct.ExampleCode Implementation.import 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; public class FileUpld{ public static void ... Read More
We can maximize windows on Chrome with a webdriver. While working on any automated test cases, if the browser opens in maximized mode then the probability of the scripts getting failed lessens.This is because if the element is visible, then the chances of its interaction increases. Also, if the window is maximized, then the testers or developers working on them gets a better visibility of the test steps.Some of the applications open in maximized mode automatically. Applying maximizing techniques on them does not have any impact on them. Let us see the methods with which we can maximize window in ... Read More
We can select the checkbox with Selenium. In an html document, each checkbox has an attribute type set to a value as checkbox. In order to select a checkbox, we shall first identify a checkbox with any locator and then apply the click() method to it.ExampleCode Implementation.import 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; public class CheckBoxSelect{ 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/selenium/selenium_automation_practice.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // identify element ... Read More
Selenium can switch to new windows when there are multiple windows opened. There may be scenarios when filling a date field in a form opens to a new window or clicking a link, button or an advertisement opens a new tab.Selenium uses the current_window_handle and window_handles methods to work with new windows. The window_handles method contains all the window handle ids of the opened windows. The window id handles are held in the form of Set data structure [containing data type as String].The current_window_handle method is used to store the window handle id of the present active window. Finally to ... Read More
The pairwise maximum refer to the values that are largest between the vectors. For example, if we have a vector that contains 1, 2, 3 and a second vector contains 2, 1, 4 then the pairwise maximum will be 2, 2, 4 because the maximum between 1 and 2 is 2, the maximum between 2 and 1 is 2, and the maximum between 3 and 4 is 4. In R, we can find these maximum values for many vectors using pmax function.Example> x1 y1 pmax(x1, y1) [1] 27 28 65 25 17 21 29 > x2 x2 [1] 7 ... Read More
The right click is performed on any element on the web page to display its context menu. For example, if we right click on an edit box, a new menu with multiple options gets displayed.Selenium uses the Actions class to perform the right click action. The contextClick() is a method under Actions class to do the right click and once the menu opens, we can select an option from them via automation.First we need to move the mouse to the middle of the element with moveToElement() method, then do the right click. Next with build() method we shall carry out ... Read More
Whenever we encounter a failure during testing, it is a common nature to capture the screenshots wherever there is a deviation from the expected result. Thus it is considered a mandatory step to attach a screenshot for creating a bug.While automating a bunch of test cases of a considerable number, capturing screenshot is critical to infer why a test case has failed for both the development and testing team. As they debug the failures, going through the screenshot and conclude if the failure is due to script issue or defect in the application.Sometimes we may need to capture the screenshots ... Read More
We can fetch href links in a page in Selenium by using the method find_elements(). All the links in the webpage are designed in a html document such that they are enclosed within the anchor tag.To fetch all the elements having tagname, we shall use the method find_elements_by_tag_name(). It will fetch a list of elements of anchor tag name as given in the method argument. If there is no matching tagname in the page, an empty list shall be returned.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.maximize_window() driver.get("https://www.google.com/") # identify elements with tagname lnks=driver.find_elements_by_tag_name("a") # traverse ... Read More
Suppose we have a bitonic sequence, we have to find the Bitonic Point in it. As we know a Bitonic Sequence is a sequence of numbers which is first strictly increasing then after a certain point it is strictly decreasing. This point is bitonic point. For only increasing or only decreasing sequences, bitonic points are not available.So, if the input is like [7, 8, 9, 12, 10, 6, 3, 2], then the output will be 12To solve this, we will follow these steps −define a function binary_search(array, l, r)if l array[m + 1], then −return mif array[m] < array[m ... Read More
Suppose we have two numbers a and b, we have to find an array containing values in range [1, a] and requires exactly b number of calls of recursive merge sort function.So, if the input is like a = 10, b = 15, then the output will be [3, 1, 4, 6, 2, 8, 5, 9, 10, 7]To solve this, we will follow these steps −Define a function solve() . This will take left, right, array, bif b < 1 or left + 1 is same as right, thenreturnb := b - 2mid := (left + right) / 2temp := ... Read More