Set Window Size Using PhantomJS and Selenium WebDriver in Python

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:46:54

341 Views

We can set window size using PhantomJS and Selenium webdriver in Python. To work with the PhantomJS, we should create a driver object of the webdriver.PhantomJS class.Then pass the path of the phantomjs.exe driver file as a parameter to the Class. Next, to set the window size, we shall use the set_window_size method and pass the dimensions as parameters to the method.To obtain the window size of the browser, we can use the get_window_size method.Syntaxdriver.set_window_size(800, 1000) print(driver.get_window_size())Examplefrom selenium import webdriver #set phantomjs.exe path driver = webdriver.PhantomJS(executable_path="C:\phantomjs.exe") driver.maximize_window() #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #set new window size driver.set_window_size(800, 880) #obtain window size print(driver.get_window_size()) ... Read More

Get Firefox Working with Selenium WebDriver on Mac OSX

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:46:38

4K+ Views

We can get Firefox working with Selenium webdriver on Mac OS. For Firefox versions which are greater than 47, the geckodriver.exe file is to be used. We shall be able to launch the browser only after creating an object of the FirefoxDriver class.SyntaxWebDriver driver=new FirefoxDriver();Visit the link −  https://www.selenium.dev/downloads/ and go to the Browser segment. Click on the Documentation link below Firefox.In the Supported platforms page, click on geckodriver releases link.Then click on the link corresponding to Mac OS.Once downloaded, extract the file and save the geckodriver.exe file to the /usr/local/bin location. As in Windows, we do not need to ... Read More

Add Custom ExpectedConditions for Selenium

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:46:26

1K+ Views

We can add custom ExpectedConditions for Selenium webdriver. We require this custom ExpectedConditions when the default expected conditions provided by webdriver are not enough to satisfy some scenarios.The method until is used which is a part of the WebDriverWait class. Here, the ExpectedConditions are used to wait for a specific criteria to be satisfied. This method pauses whenever one of the below incidents happen −The timeout duration specified has elapsed.The criteria defined yields neither false nor null.We can have a custom ExpectedCondition by creating an object of expected criteria and by taking the help of apply method.Let us take an ... Read More

Find 2^2 = a * b in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:45:39

139 Views

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

Find A and B from List of Divisors in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:42:59

174 Views

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

Find A B M Where A is Very Large in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:42:43

247 Views

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

Final String After Performing Given Operations in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:42:25

221 Views

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

Mute All Sounds in Chrome WebDriver with Selenium

Debomita Bhattacharjee
Updated on 30-Jan-2021 13:11:00

1K+ Views

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

Make Selenium Wait for 10 Seconds

Debomita Bhattacharjee
Updated on 30-Jan-2021 13:09:26

12K+ Views

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

Maximize WebDriver in Selenium 2 Using Python

Debomita Bhattacharjee
Updated on 30-Jan-2021 13:07:39

314 Views

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

Advertisements