Found 190 Articles for Selenium Web Driver

How to deal with reusable components in Selenium Java?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:05:37

815 Views

We can deal with reusable components in Selenium Java with the help of inheritance concept. It is a parent child relationship where the child class inherits the properties and methods of the parent class.ExampleFor Parent class.import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Baseclass {    public void login() throws IOException {       Properties prop = new Properties();       //Reading values from property file       FileInputStream ips = new FileInputStream(       "C:\Users\ghs6kor\eclipse- workspace\Inheritance\config.properties");       prop.load(ips);       System.setProperty("webdriver.gecko.driver",       ... Read More

How to handle proxy in Selenium in Java?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:02:55

1K+ Views

We can handle proxy in Selenium in Java with the help of PROXY class.import java.io.IOException; import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class ProxySelJav {    public static void main(String[] args) {       // TODO Auto-generated method stub       WebDriver driver;       String prox = "localhost:8080";       // set browser settings with Desired Capabilities       Proxy p = new Proxy(); p.setHttpProxy(prox).setFtpProxy(prox).setSslProxy(prox)       .setSocksProxy(prox);       DesiredCapabilities c = new DesiredCapabilities();       c.setCapability(CapabilityType.PROXY, p);       // utilize capabilities on launching ... Read More

How to take care of SSL certificate issues in chrome browser in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:01:15

495 Views

We can face SSL certificate issue because of the reasons listed below −While the website was developed, its SSL certificate was not proper.The site may have a self-signed certificate.SSL not configured properly at the server level.Exampleimport org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class SSLCert {    public static void main(String[] args) {       // TODO Auto-generated method stub       //Desired capabilities for general chrome profile       DesiredCapabilities c=DesiredCapabilities.chrome();       c.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);       c.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);       //ChromeOptions for local browser       ... Read More

How to use the Properties file to declare global variables in a framework in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:59:39

1K+ Views

We can declare global variables in Selenium with the help of the Properties class which works with .properties file. In the .properties file, the data is stored in key value pairs. We can read and write values in the .properties file.Eaxmpleimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Propert {    public static void main(String[] args) throws IOException {       // TODO Auto-generated method stub       Propert t = new Propert();       t.login();    }    public void login() throws IOException {       Properties ... Read More

How to capture screenshots in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:55:19

231 Views

We can capture screenshots in Selenium with the help of TakesScreenshot interface. For capturing the screenshot and holding it in a specific location, getScreenshotAs() method is used.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; public class ScreenshotFull{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/questions/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       // capture screenshot with getScreenshotAs() and store in the //Screenshots folder   ... Read More

How to verify if we can select multiple options in a static dropdown in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:53:30

1K+ Views

We can verify if we can select multiple options in a static dropdown in Selenium with the help of isMultiple() method. It returns a Boolean value of true or false.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 java.util.List; import org.openqa.selenium.support.ui.Select; public class OptionsMultiple{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/tutor_connect/index.php";       Select s = new Select(driver.findElement(By.xpath("//select[@name=’selType’]")));       // isMultiple() returns a boolean value       boolean result = s.isMultiple();       ... Read More

How will you select a particular value in a dropdown without using the methods of Select class in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:52:02

4K+ Views

We can select a particular value in a dropdown using the method of Select class by using findElements() method.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 java.util.List; import org.openqa.selenium.support.ui.Select; public class OptionsClick{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/tutor_connect/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       // getting the list of elements with the xpath       List opt = driver.findElements(By.xpath("//select[@name=’selType’]//option"));       int s = opt.size();       ... Read More

How to select a value from a static dropdown in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:49:55

9K+ Views

The various methods available under Select class in Selenium to select avalue from a static dropdown. They are as listed below −selectByVisibleText(String args)This method is most commonly used in dropdowns. It is very simple to select an option in a dropdown and multiple selection box with this method. It takes a String parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByVisibleText("Selenium");selectByIndex(String args)This method takes the index of the option to select in the dropdown. It takes an int parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByIndex(1);selectByValue(String args)This method takes the value ... Read More

How to get all the options in the dropdown in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:46:37

17K+ Views

We can extract all the options in a dropdown in Selenium with the help of Select class which has the getOptions() method. This retrieves all the options on a Select tag and returns a list of web elements. This method does not accept any arguments.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 java.util.List; import org.openqa.selenium.support.ui.Select; public class DropdownOptions{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = " https://www.tutorialspoint.com/tutor_connect/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);     ... Read More

What are the various methods available under Select class in Selenium?

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:44:02

767 Views

The various methods available under Select class in Selenium are listed below −selectByVisibleText(String args)This method is most commonly used in dropdowns. It is very simple to select an option in a dropdown and multiple selection box with this method. It takes a String parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByVisibleText("Selenium");selectByIndex(String args)This method takes the index of the option to select in the dropdown. It takes an int parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByIndex(1);selectByValue(String args)This method takes the value of the option to select in the dropdown. It ... Read More

Advertisements