Found 871 Articles for Automation Testing

Can Selenium interact with an existing browser session?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:04:23

4K+ Views

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

How do I set the Selenium webdriver get timeout?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:04:07

5K+ Views

We can set the Selenium webdriver to get timeout. There are numerous methods to implement timeouts. They are listed below −setScriptTimeout.pageLoadTimeout.implicitlyWait.The setScriptTimeout is the method to set the time for the webdriver. This is usually applied for an asynchronous test to complete prior throwing an exception. The default value of timeout is 0.This method is generally used for JavaScript commands in Selenium. If we omit setting time for the script, the executeAsyncScript method can encounter failure due to the more time consumed by the JavaScript to complete execution.If the timeout time is set to negative, then the JavaScript can execute ... Read More

How to execute a Javascript function in Python with Selenium?

Debomita Bhattacharjee
Updated on 01-Feb-2021 12:00:11

2K+ Views

We can execute a JavaScript function in Python with Selenium webdriver. DOM interacts with the elements via JavaScript. Selenium is capable of executing JavaScript commands with the execute_script method.Few actions like web scrolling cannot be done by Selenium directly. For this, we shall use the JavaScript Executor. We shall take the help of the JavaScript command window.scrollTo and pass it to the execute_script method. To scroll to the bottom of the page, we have to pass 0 and document.body.scrollHeight as parameters to the window.scrollTo.Syntaxdriver.execute_script("window.scrollTo(0, document.body.scrollHeight);")Examplefrom selenium import webdriver driver = webdriver.Firefox(executable_path="C:\geckodriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/index.htm") #scroll till page bottom driver.execute_script("window.scrollTo(0, document.body.scrollHeight);)We can ... Read More

What are the prerequisites to learn Selenium?

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:59:55

2K+ Views

We shall explore the prerequisites to learn Selenium. First of all, we should know that testing can be divided into two segments − Manual and Automation.For manual testing, it is essential to have the basic understanding of the application that we are going to test, a reasonable acumen and a good documentation skill.For automation testing, we should learn and develop skills on the basic testing along with automation testing concepts. Apart from these, we should have understanding on the below topicss −DatabaseProgramming logicData StructureFront End Development.Now let us see what major topics we should know under the basic testing concepts ... Read More

How does the Selenium WebDriver work?

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

259 Views

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

What is the difference between mocha and Selenium?

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:51:55

340 Views

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

The best way to inspect HTTP response headers with Selenium

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:51:00

3K+ Views

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

How do I automatically download files from a pop up dialog using selenium-python?

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:47:42

2K+ Views

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

How to add custom ExpectedConditions for Selenium?

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

927 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

How to get Firefox working with Selenium WebDriver on Mac OSX?

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

3K+ 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

Advertisements