Found 456 Articles for Software Testing

Why do we use WebDriver instead of Selenium IDE?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:21:11

438 Views

We can use webdriver instead of Selenium IDE. The Selenium IDE is a record and playback tool but not dependable. The web elements which are dynamic cannot be handled well with Selenium IDE.Selenium IDE can be used for an easy solution to automation, but for a full regression suite, Selenium webdriver should be used. Some of the differences between Selenium IDE and Selenium webdriver are −Sl. No.Selenium IDESelenium Webdriver1.It supports only Firefox.It supports all the major browsers.2.Simply a record and playback tool.Not a record and playback tool.3.Architecture based on Javascript.Architecture not based on Javascript. Communicates with browser applications.4.Does not support ... Read More

Can I set any of the attribute value of a WebElement in Selenium?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:20:07

6K+ Views

We can set any attribute value of a webelement in Selenium. Selenium 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 identify the element with the help of the Javascript method document.getElementsByClassname. It returns a list of elements, to point to the first element we shall add index [0]. To set the attribute we shall use the setAttribute method.Syntax for setting the style attribute −JavascriptExecutor j = (JavascriptExecutor) driver; js.executeScript ("document.getElementsByClassName('heading')[0].setAttribute('style', 'background-color: red')");Let us set the background color of webelement to red.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; ... Read More

How to wait for options in a select to be populated in Selenium?

Debomita Bhattacharjee
Updated on 30-Nov-2020 10:17:16

3K+ Views

We can wait for options in a select tag to be populated with Selenium. This can be done with the explicit wait concept in synchronization. The explicit wait is designed on the expected condition for an element.To wait for the options, we shall verify if presenceOfNestedElementsLocatedBy is available within the explicit wait time. We shall implement the entire verification within the try catch block.Let us see if the options are available for selection in the Continents dropdown. The ExpectedCondition along with WebDriverWait is used for explicit wait.HTML code of the select dropdown.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import ... Read More

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

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

292 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

736 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

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

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

671 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

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

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

Advertisements