package com.objects;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import com.tests.BaseClass;
public class LinkedInHomePage extends BaseClass {
public LinkedInHomePage(WebDriver driver) {
PageFactory.initElements(driver, this);
}
@FindBy(how = How.ID, using = "firstName-coldRegistrationForm")
public WebElement newFirstNameTexthBox;
@FindBy(how = How.NAME, using = "lastName")
public WebElement newLastNameTexthBox;
@FindBy(how = How.ID, using = "email-coldRegistrationForm")
public WebElement newEmailTexthBox;
@FindBy(how = How.ID, using = "password-coldRegistrationForm")
public WebElement newPasswordTexthBox;
@FindBy(how = How.ID, using = "btn-submit")
public WebElement signUpButton;
public void EnterNewFirstName(String inComingNewFirstName) {
newFirstNameTexthBox.clear();
newFirstNameTexthBox.sendKeys(inComingNewFirstName);
}
public void EnterNewLastName(String inComingNewLastName) {
newLastNameTexthBox.clear();
newLastNameTexthBox.sendKeys(inComingNewLastName);
}
public void EnterNewEmail(String inComingNewEmail) {
newEmailTexthBox.clear();
newEmailTexthBox.sendKeys(inComingNewEmail);
}
public void EnterNewPassword(String inComingNewPassword) {
newPasswordTexthBox.clear();
newPasswordTexthBox.sendKeys(inComingNewPassword);
}
public void ClickSignUp() {
signUpButton.click();
}
public void JoinNow(String FName, String LName, String Email,
String Password) {
EnterNewFirstName(FName);
EnterNewLastName(LName);
EnterNewEmail(Email);
EnterNewPassword(Password);
ClickSignUp();
}
}使用Java數組或列表,以填補硒頁面設計的頁面上的文本框對象模型
上面你可以看到的JoinNow()函數有多個參數,它工作完美的罰款。我想使用數組或列表來減少參數的數量,然後使用循環來填充文本框。我想完成類似如下的操作,但由於我使用的是頁面對象模型設計,因此無法使用findElement。
@SuppressWarnings("unchecked")
protected void JoinNow(String... var) {
List<MyElements> inputElements = new ArrayList<MyElements>();
inputElements.add((MyElements) driver.findElement(By
.id("firstName-coldRegistrationForm")));
inputElements.add((MyElements) driver.findElement(By.id("lastName")));
inputElements.add((MyElements) driver.findElement(By
.id("email-coldRegistrationForm")));
inputElements.add((MyElements) driver.findElement(By
.id("password-coldRegistrationForm")));
for (int i = 0; i < var.length; i++) {
((WebElement) inputElements.get(i)).sendKeys(var[i]);
}
}
我很困惑,其中的代碼段第二屆「保護無效JoinNow」所在。驅動程序的引用來自哪裏? – 2015-02-11 00:14:02
第二個JoinNow(String ... var)就是我在實現頁面對象模型設計之前使用的東西,現在不再使用了 – user3325340 2015-02-11 00:17:31