Thursday, September 10, 2015
Wednesday, September 9, 2015
Selenium : Change execution speed in Java (Set Speed)
Change execution speed in Java (Set Speed)
Create a new class "_WebDriver" which extends FireFoxDriver. Inside "_WebDriver" class override method "findElement" and introduce a delay inside it.
public class Main_class{
public static void main(String[] args)
{
WebDriver driver=new _WebDriver(200);
driver.get("https://in.yahoo.com/");
driver.findElement(By.id("UHSearchBox")).sendKeys("address1");
driver.findElement(By.id("UHSearchWeb")).click();
}
}
//---------Create a new Java File
public class _WebDriver extends FirefoxDriver {
private int set_speed=0;
public _WebDriver(int set_speed) //Constructor to initialize the speed
{
this.set_speed=set_speed;
}
@Override
public WebElement findElement(By by) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
return by.findElement((SearchContext) this);
}
}
Selenium : Passing Arguements using "By" class
Passing locator Arguments using "By" class
Passing locator in Selenium before its existence .(small snippet below)
public static void main(String args[])
{
Lib base_Library=new base_Library();
base_Library.wait_to_load(By.id("templateCombobox"));
}
public void wait_to_load(By by){
WebDriverWait wait = new WebDriverWait(driver,10); wait.until(ExpectedConditions.elementToBeClickable(by));
}
}
Selenium : Using FireFox and Chrome inbuilt Inspector and Xpath evaluator
Using FireFox inbuilt Inspector and Xpath evaluator
Steps below
- Launch Firefox (I'm using 40.0.3)
- Open url "google.co.in"
- Goto Tools >Web Developer>Inspector
Similar to Firebug , user can use crosshair in the console to target a particular element.
To Verify Xpath :
- In the above console
- Click on ">Console" tab
- type - $x("//input[@type='submit']")
- Press "Enter"
Syntax : $x("xpath")
For Chrome (same as Firefox)
Method 1:
Install Chropath extension for Chrome
Rt ck on web page
Ck on inspect
In Developer window , click on ">>" symbol
Select chropath
Method 2 :
User can goto :
- Settings>More tools >Developer tools
- Elements > Control+F to open search box
- Type in your xpath Eg : .//input[@type='password']
- User can also validate Xpath using "Console" tab similar to FireFox
Rest is same as FireFox.
You can also try:
You can also try:
- Press F12 to open Chrome Developer Tool
- In "Elements" panel, press Ctrl+F
- In the search box, type in XPath or CSS Selector, if elements are found, they will be highlighted in yellow.
Subscribe to:
Posts (Atom)