Selenium WebDriver在DocuSign文档上单击此处(动态ID)

时间:2014-07-14 19:15:04

标签: java selenium selenium-webdriver testng docusignapi

我需要帮助在docuSign文档中单击此动态ID。下面的代码将引导您访问docuSign文档,我只需要知道如何单击Sign Here图像(在第2页),因为每个签名的id总是不同的。测试docuSign的URL是https://www.docusign.com/demo。这是我试图执行的@Test:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


public class DocusignDemo {

WebDriver driver;
final String url = "https://www.docusign.com/demo";
final String firstName = "first_name";
final String lastName = "last_name";
final String email = "email";
final String phNumber = "phone";
final String jobTitle = "title";
final String company = "company";
final String signItNowButton = "submit_trial_form";
final String reviewDocButton = "ds_hldrBdy_dlgStart_startReview_btnInline";

@BeforeTest
public void setup() {
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
}

@AfterTest
public void teardown() {
    driver.quit();
}

@Test
public void docuSign() {
    driver.get(url);
    sendKeys(firstName, "First");
    sendKeys(lastName, "Last");
    sendKeys(email, "first@last.com");
    sendKeys(phNumber, "555-555-5555");
    sendKeys(jobTitle, "Job");
    sendKeys(company, "Company");
    clickIt(signItNowButton);
    clickIt(reviewDocButton);
    /*
     * How do I click the Sign here image because the id is dynamic and
     * keeps changing"
     */
}

public void sendKeys(String idX, String keys) {

    driver.findElement(By.id(idX)).sendKeys(keys);
}

public void clickIt(String idX) {

    WebDriverWait wait = new WebDriverWait(driver, 30);

    wait.until(ExpectedConditions.elementToBeClickable(By.id(idX)));

    driver.findElement(By.id(idX)).click();
}

}

2 个答案:

答案 0 :(得分:1)

您可以使用以下内容:

driver.findElement(By.xpath("//input[@tabtype='SignHere']")).click();

答案 1 :(得分:0)

你为什么不在课堂上给它打电话?

driver.findElement(By.partialLinkText("Sign Here")).click();