In this tutorial, we are going to write a program to evaluate the equation 2^(2^A) % B.We are going to find the value of the equation using a recursive function. Let's see the steps to solve the problem.Write a recursive function that takes 2 arguments A and B.If A is 1, then return 4 % B as 2^(2^1) % B = 4 % B.Else recursively call the function with A-1 and b.Return the result^2%B.Print the solutionExampleLet's see the code. Live Demo#include using namespace std; long long solveTheEquation(long long A, long long B) { // 2^(2^1) % B = 4 ... Read More
In this tutorial, we are going to solve the below problem.Given an array of integers, we have to find two numbers A and B. All the remaining numbers in the array are the divisors of A and B.If a number is a divisor of both A and B, then it will present twice in the array.Let's see the steps to solve the problem.The max number in the array is one of the numbers from A and B. Let's say it is A.Now, B will be the second-largest number or the number which is not a divisor of A.ExampleLet's see the ... Read More
In this tutorial, we are going to solve the equation (ab)%m where a is a very large number.The equation (ab)%m=(a%m)*(a%m)...b_times. We can solve the problem by finding the value of a%m and then multiplying it b times.Let's see the steps to solve the problem.Initialize the numbers a, b, and m.Write a function to find the a%m.Initialize the number with 0.Iterate over the number in string format.Add the last digits to the number.Update the number with number modulo them.Get the value of a%m.Write a loop that iterates b times.Multiply the a%m and modulo the result with m.Print the result.ExampleLet's see the ... Read More
In this tutorial, we are going to solve the following problem.Given a string containing only characters a and b, our task is to delete the sub-string ab from the string. And print the remaining string.Here, the idea is very simple to solve the problem. Every string with only a's and b's will shrink to either a's or b's at the end.Let's see the steps to solve the problem.Initialize the string.Initialize two counter variables for a and b.Iterate over the given string.Count the a's and b'sFind the maximum from the a and b frequencies.Print the difference between the two.ExampleLet's see the ... Read More
We can mute all sounds in Chrome with Selenium webdriver. To mute the audio we have to set parameters for the browser. For Chrome, we shall use the ChromeOptions class.We shall create an object of the ChromeOptions class. Then utilize that object to invoke the addArguments method. Then pass −mute−audio as a parameter to that method. Finally, send this information to the driver object.SyntaxChromeOptions op = new ChromeOptions(); op.addArguments("−−mute−audio"); WebDriver d = new ChromeDriver(op);For Firefox, we shall use the FirefoxOptions class and create an object for that class. Then utilize that object to invoke the addPreference method and pass media.volume_scale ... Read More
We can make Selenium wait for 10 seconds. This can be done by using the Thread.sleep method. Here, the wait time (10 seconds) is passed as a parameter to the method.We can also use the synchronization concept in Selenium for waiting. There are two kinds of wait − implicit and explicit. Both these are of dynamic nature, however the implicit wait is applied to every step of automation, the explicit wait is applicable only to a particular element.ExampleCode Implementation with sleep method.import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class WaitThrd{ public static void main(String[] args) throws ... Read More
We can maximize browser window with Selenium webdriver in Python. It is a good practise to maximize the browser while running the tests to reduce the chance of failure.Once a browser is maximized, the majority of elements become visible to the screen and the probability of interaction with the driver increases. Also, with a maximized browser, users have a better view of the elements on the page.Some of ways of maximizing browser −With the maximize_window methodSyntaxdriver.maximize_window()With the fullscreen_window methodSyntaxdriver.fullscreen_window()ExampleCode Implementation with maximize_window()from selenium import webdriver #set chromedriver.exe path driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # maximize browser driver.maximize_window() driver.get("https://www.tutorialspoint.com/index.htm") driver.close()ExampleCode Implementation with ... Read More
We can take a screenshot of a full page with Selenium webdriver in Python with chromedriver. First of all, we shall obtain the original window size with the get_window_size method.Then with the help of JavaScript Executor we shall fetch the complete height and width of the page which is opened on the browser. Then set the window size to that dimension with the set_window_size method.Next, capture the screenshot of the entire content within the body tag in the html with the screenshot method. This method accepts the path of the screenshot that will be captured as a parameter.Examplefrom selenium import ... Read More
We can start the Selenium browser(like Firefox) in minimized mode. This will be achieved by taking the help of the Dimension class. We shall create an object of this class.While creating the object , we shall pass the dimensions of the browser size as parameters to the Dimension class. Finally pass the object as parameter to the setSize method.SyntaxDimension s = new Dimension(100, 200); driver.manage().window().setSize(s);Exampleimport org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Dimension; public class FirefoxBrwSize{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new ... Read More
We can PID of browsers launched by Selenium webdriver. First of all, we have to create an object of the webdriver. Next, for example, to launch the browser in the Firefox browser, we have to take the help of webdriver.Firefox() class.The location of the geckodriver.exe file is passed as a parameter to that class. This is done by setting the path to executable_path property. Then, the browser shall be launched with the get method.Finally, to obtain the PID of the browser, we shall use the driver.service.process.id method.Syntaxs = driver.service.process.pidExamplefrom selenium import webdriver #path of geckodriver.exe driver = webdriver.Firefox(executable_path="C:\geckodriver.exe") #launch browser ... Read More