Post

1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

By Rafaela Azevedo
Hello guys, today I will post about DOM, what is and where you will use on Automation.
What is the Document Object Model?
The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page.
Why the Document Object Model?
“Dynamic HTML” is a term used by some vendors to describe the combination of HTML, style sheets and scripts that allows documents to be animated.DOM lookups in a view
Let’s look at some example code. The first thing you can do is to create a container class called LoginContainer. This class is used to find the DOM elements of the Login View. For the DOM lookup, you can use the @FindBy annotation, which takes parameters specifying what to find. In Listing 10, we use the How parameter for the lookup and using as the lookup variable. How options include CSS, ID, and XPATH.
Listing 10. LoginContainer with DOM lookups on Ruby, Cucumber and Selenium
@FindBy(how = How.ID, using = “LoginPage”)
public WebElement loginPageDiv;

@FindBy(how = How.CSS, using = “#LoginPage input[name=username]”)
public WebElement usernameInput;

@FindBy(how = How.CSS, using = “#LoginPage input[name=password]”)
public WebElement passwordInput;

@FindBy(how = How.CSS, using = “#LoginPage span[role=’button’]”)
public WebElement submitButton;

A more generically class on Java and Selenium to Find a Element
public void FindElement(Parameters_Config configParam, String idName,
String findBy) throws IOException, Exception {
switch (findBy) {

case “linkText”:
try {
configParam.driver.findElement(By.linkText(idName));
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;

case “className”:
try {
configParam.driver.findElement(By.className(idName));
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;

case “id”:
try {
configParam.driver.findElement(By.id(idName));
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;

case “cssSelector”:
try {
configParam.driver.findElement(By.cssSelector(idName));
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;

case “tagName”:
try {
configParam.driver.findElement(By.tagName(idName));
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;

case “xpath”:
try {
configParam.driver.findElement(By.xpath(idName));
} catch (Exception e) {
System.out.println(e.getMessage());
}
break;

default:
Exception e = new Exception();
System.out.println(e.getMessage());
break;
}
}

Thank you :)
Font: http://www.w3.org/DOM/

Source: http://azevedorafaela.wordpress.com/2014/06/20/using-dom-on-selenium/

Category: Programming, QA, Test and Automation Stuffs, dom, example class find element cucumber, example class find element java, example class find element ruby, example class find element selenium, example class findby cucumber, example class findby java, example class findby ruby, example class findby selenium, example class findelement cucumber, example class findelement java, example class findelement ruby, example class findelement selenium, example java class find element selenium, example java class findby selenium, example java class findelement selenium, find element cucumber, find element java, find element java and selenium, find element ruby, find element ruby selenium cucumber, find element selenium, java example dom, java example dom selenium, ruby example dom, ruby example dom cucumber, sample class find element cucumber, sample class find element java, sample class find element ruby, sample class find element selenium, sample class findby cucumber, sample class findby java, sample class findby ruby, sample class findby selenium, sample class findelement cucumber, sample class findelement java, sample class findelement ruby, sample class findelement selenium, using dom selenium, using dom with selenium, what is document object model, what is dom

Você também pode querer ler

Comments are off for this post.