We can resolve StaleElementReferenceException in Selenium webdriver. The term stale means something which is not fresh and decayed. Thus a stale element points to an element which is not present any more.There may be a case, when an element was in DOM initially but after modifications in Document Object Model (DOM), the element becomes stale and the StaleElementReferenceException is thrown if we make an attempt to access this element.This exception is caused whenever an element is not present in the DOM, or deleted. We can handle this exception by the following ways −Refreshing the page and verifying again.Implement retry method.ExampleCode ... Read More
In this tutorial, we are going to write a program that finds all the divisors of a natural number. It's a straightforward problem. Let's see the steps to solve it.Initialize the number.Write a loop that iterates from 1 to the square root of the given number.Check whether the given number is divisible by the current number or not.If the above condition satisfies, then print the current number and given_number/current_number.ExampleLet's see the code. Live Demo#include using namespace std; void findDivisors(int n) { for (int i = 1; i
In this tutorial, we are going to write a program that finds all the divisors of a natural number. It's a straightforward problem. Let's see the steps to solve it.Initialize the number.Write a loop that iterates from 1 to the given number.Check whether the given number is divisible by the current number or not.If the above condition satisfies, then print the current number.ExampleLet's see the code. Live Demo#include using namespace std; void findDivisors(int n) { for (int i = 1; i
In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements that iterate until the end of the array.Add the three elements.Compare the sum with 0.If both are equal, then print the elements and break the loops.ExampleLet's see the code. Live Demo#include using namespace std; void findTripletsWithSumZero(int arr[], int n){ bool is_found = false; for (int i = 0; i < n-2; i++) { ... Read More
We can click on the hidden element in Selenium webdriver. In DOM, the hidden elements are the ones which are not displayed on the page. CSS property style should have the value display:none set for the hidden elements. Also, if the hidden element resides within a form tag, it can be made hidden by setting the attribute type to hidden.ElementNotVisibleException is thrown by Selenium while handling hidden elements. So JavaScript Executors can be utilized to access and handle these elements. The executeScript method is used in Selenium to execute the JavaScript commands. The commands to be executed are passed as ... Read More
We can convert commands recorded in Selenium IDE to Java. To convert commands first navigate to File menu, then select the option Export Test case As.After clicking it, all the possible options for conversion get displayed. Choose the option Java/ Junit 4/ WebDriver.Finally, we have to save the file with the .java extension. Then we can open this file using a text Editor or IDE.We can also convert commands recorded in Selenium IDE to Java by navigating to the Options menu. As the Selenium IDE Options pop−up comes up, select the checkbox Enable experimental features. Then click on OK.Next, select ... Read More
In this tutorial, we are going to write a program that finds the number whose XOR operation with the given number is maximum.We are assuming the number of bits here is 8.The XOR operation of different bits gives you the 1 bit. And the XOR operation between the same bits gives you the 0 bit.If we find the 1's complement of the given number, then that's the number we are looking for.ExampleLet's see the code. Live Demo#include using namespace std; int findNumberWithMaximumXOR(int X) { return ((1
In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements which iterate until the end of the array.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code. Live Demo#include using namespace std; bool findTriplet(int arr[], int arr_size, int sum) { for (int i = 0; i < arr_size - 2; i++) { ... Read More
In this tutorial, we are going to write a program that finds the triplet in the linked list whose sum is equal to the given number.Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Write three inner loops for three elements which iterate until the end of the linked list.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code. Live Demo#include using namespace std; class Node { public: int data; Node* next; ... Read More
We can interact with an existing browser session. This is performed by using the Capabilities and ChromeOptions classes. The Capabilities class obtains the browser capabilities with the help of the getCapabilities method.This is generally used for debugging purposes when we have a large number of steps in a test and we do not want to repeat the same steps. First of all we shall launch the browser and enter some text in the below edit box.Exampleimport org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.Capabilities; import org.openqa.selenium.By; import java.util.Map; import java.util.concurrent.TimeUnit; public class ConnectExistingSession{ public static void main(String[] args) throws ... Read More