Convert Selenium 1 RemoteControl to Selenium 2 WebDriver

Here is a more complete reference guide to converting Java Remote Control commands into Selenium 2 WebDriver Java commands. This comes straight out of the class we teach at LMN Solutions. Selenium 2 classes in Reston, VA

Description
Remote Control – Selenium 1
WebDriver – Selenium 2 Command
Get access to driver
selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://www.w3schools.com/”);
selenium.start();
FirefoxDriver driver = new FireFoxDriver(); 
InternetExplorerDriver driver = new InternetExplorerDriver();
HtmlUnitDriver driver = new HtmlUnitDriver();
OperaDriver driver = new OperaDriver();
ChromeDriver driver = new ChromeDriver();
Page Title
selenium.getTitle();
driver.getTitle();
Navigate to page
selenium.open(“http://www.google.com”);
driver.get(“http://www.google.com”);
Find element by name
element = driver.findElement(By.name(“first_name”));
Delete text from input field
selenium.type(“”);
element.clear();
Sets value of input field
selenium.type(“Brad”);
element.sendKeys(“Brad”);
Click on the element
selenium.click(“submit”);
element.click();
Note: If element is a link or button it will perform the click action
Return text between element tags
selenium.getText(“//h3[2]”);
element.getText(); 
Returns the value of the element
selenium.getValue(“first_name”);
element.getValue();
Returns true or false designating if the element is selected
selenium.isChecked(“female”);
element.isSelected();
Get the Select list value
selenium.getSelectedValue(“cars”);
Select select = new Select(element);
select.getFirstSelectedOption();
Where on the page is the top left-hand corner of the rendered element
n/a
element.getLocation();
Get the tag name of the element
n/a
element.getTagName();
Returns true or false designating if the element is displayed
selenium.isVisible(“hidden_field”);
element.isDisplayed();
Returns true or false designating if the element is enabled.  Will generally return true for everything but disabled input elements
selenium.isEditable(“last_name”);
element.isEnabled();
Width and height of the rendered element
Almost equivalent
selenium.getAttribute(“first_name@maxlength”);
element.getSize();
Returns the attribute
<input type=”text” value=”Joe” name=”FirstName>
selenium.getAttribute(“FirstName@value”);
element.getAttribute(“value”);
Submits the form if element is a form or within a form
selenium.submit(“first_name”);
element.submit();
Alerts
selenium.chooseOkOnNextConfirmation();
selenium.chooseCancelOnNextConfirmation();
Alert alert = driver.switchTo().alert();
alert.accept();
alert.dismiss();
Frames
selenium.selectFrame(“relative=up”);
selenium.selectFrame(“showframe”);
driver.switchTo.defaultContent();
driver.switchTo.frame(“showframe);
Double Click
selenium.doubleClick(“aButton”);
Actions action = new Actions(driver);
action.doubleClick(addElement);
Element Present
selenium.isElementPresent();
Try {
   element = driver.findElement(By.name(“name”));
} catch (NoSuchElementException e) {
   fail(“name – no such element”);
}

© Copyright 2012 LMN Solutions

If you  have a question e-mail us or add a comment.

 
 
 

LMN Solutions – Find out more about us.
Selenium Training

selenium@lmnsolutions.com
Leave Yours +

No Comments

Comments are closed.

  • Comments are Closed