Selenium Webdriver And Xstudio

Find the data you need here

We provide programming data of 20 most popular languages, hope to help you!

Previous PostNext Post

Selenium WebDriver Tutorial : Getting Started with Test Automation

The browser then starts receiving the request through its driver. Let’s take an example with the code snippet below: WebDriver driver = new ChromeDriver (); driver. get (https://www.browserstack.com) As soon as you complete writing …

WebDriver driver = new ChromeDriver ();
driver. get (https://www.browserstack.com)
https://localhost:8080/{"url":https://www.browserstack.com"}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class LoginAutomation {
@Test
public void login() {
System.setProperty("webdriver.chrome.driver", "path of driver");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.browserstack.com/users/sign_in");
WebElement username=driver.findElement(By.id("user_email_Login"));
WebElement password=driver.findElement(By.id("user_password"));
WebElement login=driver.findElement(By.name("commit"));
username.sendKeys("[email protected]");
password.sendKeys("your_password");
login.click();
String actualUrl="https://live.browserstack.com/dashboard";
String expectedUrl= driver.getCurrentUrl();
Assert.assertEquals(expectedUrl,actualUrl);
}
}

Selenium Webdriver Tutorial with Examples | Understanding WebDriver, WebElement

The Selenium module of Python programming language contains three crucial entities—WebDriver, WebElement, and By. The WebDriver helps us automate the browser object and has methods for it. The WebElement helps us automate the HTML element on the page, and has methods to perform an action on them. The By class helps us locate objects …

<table border="0" cellspacings="0" cellpadding="2" width="1001">
 <tr>
  <td class="fieldkey"> E-mail Address:</td>
  <td class="fieldvalue"><input type="text" name="email_address"/></td>
 </tr>
 <tr>
  <td class="fieldkey">password:</td>
  <td class="fieldvalue"><input type="password" name="password" maxlenght="40" /></td>
 </tr>
</table>
<p><a href="http://practice.bpbonline.com/catalog/password_forgotten.php">password forgotten? click here.</a></p>
<p align="right"><span class="tablink"><button id="tab1" type="sbmit">sign Inc/button></span><script>
from selenium import webdriver

browser = webdriver.chrome(executble_path='D:\Ecl.ipse\BPB\seleniumpython\seleniumpython\drivers\chromedriver.exe')
browser.get('http://practice.bpbonline.com/catalog/index.php')
browser.find_element_by_link_text("My Account").click()
browser.find_element_by_name("email_address").send_keys("[email protected]")
browser.find_element_by_name("password").send_keys("[email protected]")
browser.find_element_by_id("tab1").click( )
browser.find_element_by_link_text("tab off").click( )
browser.find_element_by_link_text("continue").click( )
browser.quit( )

First Selenium Webdriver Script: JAVA Sample Code Example

Locating GUI Elements. Locating elements in WebDriver is done by using the “findElement(By.locator())” method.The “locator” part of the code is same as any of the locators previously discussed in the Selenium IDE chapters of these tutorials. Infact, it is recommended that you locate GUI elements using IDE and once successfully identified export the code to …

package newproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//comment the above line and uncomment below line to use Chrome
//import org.openqa.selenium.chrome.ChromeDriver;
public class PG1 {


    public static void main(String[] args) {
        // declaration and instantiation of objects/variables
    	System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
		WebDriver driver = new FirefoxDriver();
		//comment the above 2 lines and uncomment below 2 lines to use Chrome
		//System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
		//WebDriver driver = new ChromeDriver();
    	
        String baseUrl = "http://demo.guru99.com/test/newtours/";
        String expectedTitle = "Welcome: Mercury Tours";
        String actualTitle = "";

        // launch Fire fox and direct it to the Base URL
        driver.get(baseUrl);

        // get the actual value of the title
        actualTitle = driver.getTitle();

        /*
         * compare the actual title of the page with the expected one and print
         * the result as "Passed" or "Failed"
         */
        if (actualTitle.contentEquals(expectedTitle)){
            System.out.println("Test Passed!");
        } else {
            System.out.println("Test Failed");
        }
       
        //close Fire fox
        driver.close();
       
    }

}
package newproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PG2 {
    public static void main(String[] args) {
    	System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
    	WebDriver driver = new FirefoxDriver();
        String baseUrl = "http://www.facebook.com";
        String tagName = "";
        
        driver.get(baseUrl);
        tagName = driver.findElement(By.id("email")).getTagName();
        System.out.println(tagName);
        driver.close();
        System.exit(0);
}
}
package newproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PG3 {
    public static void main(String[] args) {
    	System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
    	WebDriver driver = new FirefoxDriver();
        driver.get("http://www.popuptest.com/popuptest2.html");
        driver.quit();  // using QUIT all windows will close
    }
}
package newproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PG4 {
	  public static void main(String[] args) {
		  	System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");  
		  	WebDriver driver = new FirefoxDriver();
	        driver.get("http://demo.guru99.com/selenium/deprecated.html");
	        driver.switchTo().frame("classFrame");
	        driver.findElement(By.linkText("Deprecated")).click();
	        driver.close(); 
	    }
}
package mypackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class myclass {

    public static void main(String[] args) {
    	System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        String alertMessage = "";

        driver.get("http://jsbin.com/usidix/1");
        driver.findElement(By.cssSelector("input[value=\"Go!\"]")).click();
        alertMessage = driver.switchTo().alert().getText();
        driver.switchTo().alert().accept();
       
        System.out.println(alertMessage);
        driver.quit();
       
    }
}
WebElement txtbox_username = driver.findElement(By.id("username"));
try{
        if(txtbox_username.isEnabled()){
            txtbox_username.sendKeys("tutorial");
        }
    }

catch(NoSuchElementException nsee){
            System.out.println(nsee.toString());
 }

Selenium C# Webdriver Tutorial: NUnit Example

Create a new project in Visual Studio: Step 1) In the File Menu, Click New > Project. Step 2) In the next screen, Select the option ‘Visual C#’. Click on Console App (.Net Framework) Enter name as “Guru99”. Click OK. Step 3) The below screen will be displayed once the project is successfully created.

using System;
namespace FirstProgram {
class DemoPrint {
static void main(){
    Console.WriteLine("Guru99");
	}
  }
}
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guru99Demo
{
	class Guru99Demo						
    {
        IWebDriver driver;

        [SetUp]
		public void startBrowser()
        {
            driver = new ChromeDriver("D:\\3rdparty\\chrome");
        }

        [Test]
		public void test()
        {
            driver.Url = "http://www.google.co.in";
        }

        [TearDown]
		public void closeBrowser()
        {
            driver.Close();
        }

    }
}
driver.Url = "https://www.guru99.com"
String title = driver.Title
String pageSource = driver.PageSource
driver.Close();
driver.Quit();
driver.Navigate().Back();
driver.Navigate().Forward()
driver.Navigate().Refresh()
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement"));  element.Click();
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
element.Clear();
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
element.SendKeys("guru99");
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
Boolean status = element.Displayed;
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
Boolean status = element.Enabled;
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
Boolean status = element.Selected;
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement"));  element.submit();
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
String text=element.Text;
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement"));  String tagName = element.TagName;
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
String color = element.getCSSValue;
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
select.SelectByText("Guru99");
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
select.SelectByIndex("4");
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
select.SelectByValue("Guru99");
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
List<IWebelement> options = select. Options;
int size = options.Count;
for(int i=0;i<options.size();i++)
{
String value = size.elementAt(i).Text;
Console.writeLine(value);
}
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
Boolean status = select.IsMultiple();
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
select.DeSelectAll();
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
select.DeSelectByIndex("4");
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
select.DeSelectByValue("Guru99");
IWebelement element = driver.FindElement(By.xpath("xpath of Webelement")); 
SelectElement select = new SelectElement(element);
select.DeSelectByText("Guru99");
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guru99Demo
{
	class CSS						
    {
        IWebDriver m_driver;

        [Test]
		public void cssDemo()
        {
            m_driver = new ChromeDriver("D:\\3rdparty\\chrome");
            m_driver.Url = "http://demo.guru99.com/test/guru99home/";
            m_driver.Manage().Window.Maximize();
            IWebelement link = m_driver.FindElement(By.XPath(".//*[@id='rt-header']//div[2]/div/ul/li[2]/a"));
            link.Click();
            m_driver.Close();
        }
    }
}
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guru99Demo
{
	class CSS						
    {
        IWebDriver m_driver;

        [Test]
		public void cssDemo()
        {
            m_driver = new ChromeDriver("G:\\");
            m_driver.Url = "http://demo.guru99.com/test/guru99home/";
            m_driver.Manage().Window.Maximize();

             
			// Store locator values of email text box and sign up button				
            IWebElement emailTextBox = m_driver.FindElement(By.XPath(".//*[@id='philadelphia-field-email']"));
            IWebElement signUpButton = m_driver.FindElement(By.XPath(".//*[@id='philadelphia-field-submit']"));

            emailTextBox.SendKeys("[email protected]");
            signUpButton.Click();
                        
        }
    }
}			
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guru99Demo
{
	class CSS						
    {
        IWebDriver m_driver;

        [Test]
		public void cssDemo()
        {
            m_driver = new ChromeDriver("G:\\");
            m_driver.Url = "http://demo.guru99.com/test/guru99home/";
            m_driver.Manage().Window.Maximize();

             
			// Store locator values of email text box and sign up button				
            IWebElement emailTextBox = m_driver.FindElement(By.CssSelector("input[id=philadelphia-field-email]"));
            IWebElement signUpButton = m_driver.FindElement(By.CssSelector("input[id=philadelphia-field-submit]"));

            emailTextBox.SendKeys("[email protected]");
            signUpButton.Click();

             
        }
    }
}
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;


namespace Guru99Demo
{
	class TestSelect						
    {
        IWebDriver m_driver;

        [Test]
		public void selectDemo()
        {
            m_driver = new ChromeDriver("G:\\");
            m_driver.Url = "http://demo.guru99.com/test/guru99home/";
            m_driver.Manage().Window.Maximize();

            IWebElement course = m_driver.FindElement(By.XPath(".//*[@id='awf_field-91977689']"));

			var selectTest = new SelectElement(course);
			// Select a value from the dropdown				
            selectTest.SelectByValue("sap-abap");
                        
        }
    }
}

Previous PostNext Post

Related code examples