Found 190 Articles for Selenium Web Driver

Best way to take screenshot of a web page into Selenium?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:58:03

191 Views

We can take screenshots of a web page with Selenium. It is a three way process. Taking a screenshot is one of the most essential steps towards defect and failure analysis.First, we have to convert the driver object to the TakeScreenshot interface.SyntaxTakesScreenshot s = (TakesScreenshot)driver;Next, we have to take the help of the getScreenshotAs method to have an image file and finally copy the file to a location with FileUtils.copyFile method.SyntaxFile src=s.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("file path"));Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.apache.commons.io.FileUtils; import java.io.File; public class ScreenshotCapture{    public static void ... Read More

How do you use Selenium to execute javascript within a frame?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:55:57

548 Views

We can use Javascript within a frame with Selenium. It can run Javascript commands by the executeScript method. The command to be executed is passed as an argument to the method.Next, we have to return the values from the Javascript command with the return keyword. We have to take the help of the window.length command in Javascript to count the number of frames in a page.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; int i = Integer.parseInt(j.executeScript("return window.length").toString());Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class FramesJS{    public static void main(String[] args) {         ... Read More

How to record a video in Selenium webdriver?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:54:20

600 Views

We can record a video with Selenium. There is no default technique in Selenium to record videos. The videos can be captured in the below processes−ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar files need to be downloaded and saved within the project folder.Next, add the above two jars to the project Build path. Right-click on project−> Click on Properties−> Choose Java Build Path−> Click on the Libraries tab−> Click on Add External Jars−> Browser and select the ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar−> Click on Apply−> Click OK.Have a folder to hold the videos within the project.Example@BeforeMethod public void bmethod(Method m){    // format of the date ... Read More

How to select the Date Picker In Selenium WebDriver?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:52:45

6K+ Views

We can select the date picker in Selenium. It is slightly difficult to handle calendar controls as the day, month and year selection can be represented via different UI.Sometimes they are represented by the dropdown or by forward and backward controls. Let us select the date picker as shown below.From Date −To Date −Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.support.ui.Select; public class DatePicker{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String frdate = "20";     ... Read More

How do you focus on new windows with selenium ide?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:49:53

463 Views

We can focus on new windows with Selenium IDE. On clicking a link, a new tab or a window opens. After accessing the new window, we can close it and shift to the parent window.Click on a link with the below step. Visit site is the name of the link to be clicked.Select the window which opened on clicking the link.Add Event is the page title of the window opened on clicking the link. Now, we can perform actions on the new window.Close the new window with the below step.Step back to the parent window with the below step. The ... Read More

Best practice to wait for a change with Selenium Webdriver?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:48:19

3K+ Views

The best practice to wait for a change in Selenium is to use the synchronization concept. The implicit and explicit waits can be used to handle a wait. The implicit is a global wait applied to every element on the page.The default value of implicit wait is 0. Also it is a dynamic wait, meaning if there is an implicit wait of 5 seconds and the element becomes available at the 3rd second, then the next step is executed immediately without waiting for the entire 5 seconds. Once the 5 seconds have elapsed, and if element is not found, a ... Read More

How to deal with ModalDialog using selenium webdriver?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:46:45

3K+ Views

We can deal with modal dialog boxes with Selenium. A modal is just like a window that enforces the user to access it prior to going back to the actual page. It can be an authentication window as well.Let us work with the below modal dialog −Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class ModDialog{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       driver.get("http://www.uitestpractice.com/Students/Switchto");       // identify element and click       WebElement m = driver       .findElement(By.xpath("//button[contains(text(), ... Read More

How can I consistently remove the default text from an input element with Selenium?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:45:20

450 Views

We can consistently remove the default text from an input element with Selenium. The clear method is used to remove the values currently present in an edit box or a text area.The Keys.chord method along with sendKeys can also be used. The Keys.chord method allows you to pass more than one key at once. The group of keys or strings are passed as arguments to the method.First of all, pass Keys.CONTROL and a as arguments to the Keys.chord method. The whole string is then passed as an argument to the sendKeys method. Last, we have to pass Keys.DELETE to the ... Read More

How to close the pop up window in selenium running?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:42:57

6K+ Views

We can close the pop up window with Selenium. The getWindowHandles and getWindowHandle methods are used for the pop up window. To store all the window handles opened in a Set data structure, the getWindowHandles method is used.To store the window handle of the pop up in focus, the getWindowHandle method is used. To iterate over the window handles, the iterator method is used. By default, the Selenium driver has the control over the parent window.To switch the focus of the driver to the child pop up window, we can take the help of the switchTo().window method. The window handle ... Read More

How do you check scroll position using selenium?

Debomita Bhattacharjee
Updated on 28-Nov-2020 13:41:25

3K+ Views

We can check scroll position using Selenium. To check the position we shall use the Javascript executor. We have to verify the value of the window.pageYOffset in the browser.While the URL is launched, the scroll is at the top the value of window.pageYOffset is 0. As we scroll to an element, the value of the window.pageYOffset shall be greater than 0.SyntaxJavascriptExecutor j = (JavascriptExecutor) driver; Long v = (Long) j.executeScript("return window.pageYOffset;");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class ScrollPosition{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); ... Read More

Advertisements