Found 719 Articles for Testing Tools

How to get an attribute value from a href link in selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:12:48

11K+ Views

We can get an attribute value from a href link in Selenium. To begin with, we have to first identify the element having an anchor tag with the help of any of the locators like css, id, class, and so on.Next, we shall use the getAttribute method and pass href as a parameter to the method. Let us investigate an element with an anchor tag having the href attribute. Here, the value of href should contain /about/about_team.htm.ExampleCode Implementation.import 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; public class HrefValue{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); ... Read More

Human-like mouse movements with Selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:10:18

2K+ Views

We can do human-like mouse movements with Selenium. This can be done with the help of the Actions class. The human-like mouse movements include right-click, double-click, mouse movement, drag and drop, and so on.To do the mouse movement, the moveToElement method is used. To perform a right-click, the contextClick method is used. Finally, to actually execute the actions, build and perform methods should be added.Once we right-click on an element, various options get displayed. We have to add the import org.openqa.selenium.interactions.Actions package for implementing Actions.ExampleCode Implementation.import 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.interactions.Action; import org.openqa.selenium.interactions.Actions; public class RightClick{    public static void ... Read More

Selenium and Headless Environment.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:07:47

837 Views

We can execute Selenium in a headless environment. The headless execution is a new trend followed in industry today since it is fast and supports more than one browser.Firefox in headless mode, can be run once we configure the geckodriver path. We shall then use the FirefoxOptions class, and send the headless knowledge to the browser with setHeadless method and pass true as a parameter to it.SyntaxFirefoxOptions o = new FirefoxOptions(); o.setHeadless(true); WebDriver driver = new FirefoxDriver(o);ExampleCode Implementation.import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import java.util.concurrent.TimeUnit; public class HeadlessFirefox{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");     ... Read More

Downloading with chrome headless and selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:05:46

659 Views

We can download Chrome in headless mode in Selenium. The headless execution is one of the ways saving resources by not utilizing the complete graphical interface.After the version 59, Chrome can be used in headless mode. The ChromeOptions class is used to modify the default character of the browser. The parameter headless is passed as a parameter to the addArgument method for headless execution.SyntaxChromeOptions o = new ChromeOptions(); o.addArguments("headless"); WebDriver driver = new ChromeDriver(o);ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class HeadlessChrome{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");     ... Read More

Does Selenium support headless browser testing?

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:03:36

253 Views

Yes, Selenium supports headless browser testing. This can be done with the help of the HTMLUnitDriver. It is the fastest webdriver among other browser drivers and is platform independent.After Selenium 2.53 version, HTMLUnitDriver jar has to be added explicitly within the project. To add the dependency, follow the steps as listed below −Navigate to the link − https://github.com/SeleniumHQ/htmlunitdriver/releases.Click on the link highlighted in the below image.Right-click on the project and choose Build path. Then click on Configure Build Path.Go to Java Build Path, then select Libraries. Click on Add External JARs. Then browse and add the HTMLUnitDriver jar.We have to add ... Read More

Access to file download dialog in Firefox in Selenium.

Debomita Bhattacharjee
Updated on 28-Dec-2020 13:00:05

455 Views

We can access file download dialog in Firefox in Selenium. For this we have to first modify the default directory where the downloaded file gets stored. This is done by the addpreference method.p.addPreference("browser.download.folderList", 2);Then, define the new path of the download directory.Finally, we shall ignore the save to disk and open file options in dialog for the file types via their MIME code. The addPreference method can be called with the help of FirefoxOptions class.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import java.util.concurrent.TimeUnit; public class FileDwnloadWithoutDialg{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); ... Read More

How to set default download directory in selenium Chrome Capabilities?

Debomita Bhattacharjee
Updated on 28-Dec-2020 12:57:25

3K+ Views

We can set the default download directory in Selenium with Chrome capabilities. All the browsers have a download directory set by default. We can modify it via the browser settings.We can change the setting manually, but it gets modified on triggering a script. We change the directory for download in Chrome browser with the help of ChromeOptions class.We are required to add capabilities to the browser with the parameter download.default_directory. The path of the new location to be set is considered as its value.ExampleCode Implementation.import java.io.File; import org.openqa.selenium.By; import java.io.IOException; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.HashMap; import java.util.Map; public class SetDownloadPathChrome ... Read More

How can I download a file on a click event using selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 12:54:51

1K+ Views

We can download a file on a click event in Selenium. Normally, on clicking on the download link, a pop-up comes with the file name along with the Open and Save option.To download with a click event, an object of the FirefoxOptions class is to be created. Then with the addPreference method, we shall configure browser preferences.We shall mention the location where the download is to be done along with the neverAsk.openFile and neverAsk.saveToDisk preferences are to be set.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import java.util.concurrent.TimeUnit; public class FileDwnloadWithClick{    public static void main(String[] args) {   ... Read More

How do I switch to the active tab in Selenium?

Debomita Bhattacharjee
Updated on 28-Dec-2020 12:00:36

5K+ Views

We can switch to the active tab in Selenium. The methods Keys.chord and sendKeys are used to open a new tab. More than one key can be passed at once with the Keys.chord method.The Keys.CONTROL and Keys.ENTER combined are passed as parameters to the Keys.chord method. This is stored as a string and again passed as a parameter to the sendKeys method.SyntaxString tb = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.xpath("//*[text()='Company']")).sendKeys(tb);All the window ids which are opened are stored in an array list. By default, the driver has the focus on the parent window. To switch the focus to the new tab, switchTo().window method is used.The ... Read More

How to download any file and save it to the desired location using Selenium Webdriver?

Debomita Bhattacharjee
Updated on 28-Dec-2020 11:58:07

3K+ Views

We can download any file and save it to the desired location with Selenium. This can be done by creating an instance of the FirefoxOptions class. Then with the help of the addPreference method, we have to set the browser preferences.We shall also specify the path where the file has to be downloaded with the help of the addPreference method.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import java.util.concurrent.TimeUnit; public class FileDwnload{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");       // create object of FirefoxOptions class       FirefoxOptions profile = ... Read More

Advertisements