The working of Selenium webdriver is described in the below image −Source Img : https://www.tutorialspoint.com/what−is−web−driver−in−seleniumSelenium webdriver contains the below components −Selenium Binding Languages − Selenium can work on more than one language like Java, Python, C#, Ruby, and so on as it has the bindings for all these languages.JSON Wire Protocol − JavaScript Object Notation is called the JSON Wire Protocol. It dispatches data from the server to the page of the client. It is developed on REST API which carries information inside the HTTP servers.Browser Driver − Every browser has a driver with which it establishes communication. As a ... Read More
We can set a cookie to a specific domain in Selenium webdriver with Python. A cookie is used to hold information sent by the browser. A key−value pair format is utilized and it is like a message provided to the browser by the server.For cookie addition, the method add_cookie is used. The key and value are passed as parameters to the method. To get back all the cookies, get_cookies method is used. To get a specific cookie, the method get_cookie is used.To delete cookies, the method delete_all_cookies is used.Syntaxdriver.add_cookie({"Automation": "QA"}); c= driver.get_cookies(); driver.get_cookie({"Automation"); driver.delete_all_cookies();Examplefrom selenium import webdriver #set geckodriver.exe path ... Read More
The differences between Mocha and Selenium are listed below −VsFunctionalitiesMochaSeleniumPurposeIt is an easy, workable and popular JavaScript framework developed for Node.js.It is a free automation tool used for testing the web.LanguageBased on JavaScript.Can be used with multiple languages like Java, Python, C#, Ruby, JavaScript, and so on.UsageUsed for integration, unit and end to end testing.Used for web based automation testing.XUnit frameworkIt contains the XUnit reporter which yields an XML document.It cannot be used with XUnit Framework.BrowserSupports mostly Chrome and Firefox. It can be used for other browsers with certain challenges.Supports the majority of browsers like Chrome, Firefox, Safari, IE, and ... Read More
We can inspect HTTP response headers with Selenium webdriver. To verify the HTTP header, we should get the response from a source. Some of the HTTP response codes are listed below −5XX − Represents server concerns.4XX − Represents issues in resource detection.3XX − Represents response redirection.2XX − Represents correct ocde.The HttpURLConnection class is used to obtain the HTTP response code. To have a link to an URL, the method openConnection is used. Then, we have to use the setRequestMethod method and pass HEAD as parameter to it.The connect method is applied on the object of the HttpURLConnection class. Finally, the ... Read More
In this tutorial, we are going to solve the following problem.Given an array, find the number which is equal to the index. It's a straightforward problem.Iterate over the given array and return the index which is equal to the array element.ExampleLet's see the code. Live Demo#include using namespace std; int linearSearch(int arr[], int n) { for(int i = 0; i < n; i++) { if(arr[i] == i) { return i; } } return -1; } int main() { int arr[] = {10, 20, 30, 40, 50, 5, 60}; cout
In this tutorial, we are going to solve the following problem.Given an integer n, we have to find the (1n+2n+3n+4n)%5The number (1n+2n+3n+4n) will be very large if n is large. It can't be fit in the long integers as well. So, we need to find an alternate solution.If you solve the equation for the number 1, 2, 3, 4, 5, 6, 7, 8, 9 you will get 10, 30, 100, 354, 1300, 4890, 18700, 72354, 282340 values respectively.Observe the results of the equation carefully. You will find that the last digit of the equation result repeats for every 4th number. ... Read More
We can automatically download files from a pop up dialog using Selenium webdriver with Python. After clicking the download link, a dialog box appears for the user to select various options to Save the file.We have to programmatically configure the path where the download has to be performed such that every time the Firefox browser is launched, the Firefox profile is proper to perform the download at the desired location.Open the address bar of Firefox, and enter about:config and press Enter . All the browser preferences shall be available with Edit and Toggle buttons. We shall use the Firefox Options ... Read More
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
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
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