如何找到以下代码的文本区域的xpath?

时间:2014-08-12 07:09:28

标签: selenium xpath selenium-webdriver

* //这里我首先登录然后创建新的集合,然后尝试添加问题以填充空白的问题类型。

public class New_Question {
  public static void main(String[] args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.goorulearning.org");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    //Login into the application with username and password
    driver.findElement(By.id("lblLogin")).click();
    driver.findElement(By.id("tbLoginUsername")).sendKeys("khush");
    driver.findElement(By.id("tbLoginPassword")).sendKeys("gooru12");
    driver.findElement(By.id("btnLogin")).click();
    Thread.sleep(5000L);
    //Clicking on My Collection by hover on the tab- Create collection.
    Actions act = new Actions(driver);
    WebElement Myclass =driver.findElement(By.id("LinkheaderElement2"));
    act.moveToElement(Myclass).build().perform();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.id("lblLblCreateCollection")).click();
    Thread.sleep(10000L);
   // Creating Collection by name "My First Collection"
    driver.findElement(By.xpath("//input[contains(@id,'txtCollectionTitle')]"))
    .sendKeys("My First Collection");
    driver.findElement(By.id("btnOk")).click();
   // using implicit wait 
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    // Clicking on New Question button
    driver.findElement(By.id("btnNewQuestion")).click();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//a[contains(., 'Fill in the Blank')]")).click();
    // please find the xpath for Question text area. In html only class tag is given, please let me know how to find xpath for this kind of element having only class in html.
    driver.findElement(By.className("org-ednovo-gooru-client-mvp-shelf-collection-tab-resource-add-AddQuestionResourceView_AddQuestionResourceViewUiBinderImpl_GenCss_addWebResourceStyle-addResourceFormInputControl questionTextcontainer")).sendKeys("My first question---> 1+1 = ?");

}*

1 个答案:

答案 0 :(得分:0)

一个有用的插件是firebug插件,有了这个插件,你可以检查你的网站并复制一个工作的xpath。我也使用这个插件。但是如果你想拥有一个更稳定的xpath,你必须构建一个xpath结构。您应该使用此元素唯一的结构。也许是多个属性的组合。