-4

*//Here i am first login and then creating new collection and then trying to add question for fill the blank question type.

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 = ?");

}*
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Khushboo
  • 13
  • 5
  • The text are is inside the `frame`, you would need to switch to it and send keys to the appropriate element, see http://stackoverflow.com/questions/10879206/how-to-switch-between-frames-in-selenium-webdriver-using-java. – alecxe Aug 12 '14 at 07:16
  • Right click, Inspect Element, Right click and Copy Xpath? – Decypher Aug 12 '14 at 07:40
  • I tried driver.switchTo().frame(driver.findElement(By.id("gwt-uid-977_ifr"))); after switching to frame also i am unable to click on fill in the blank tab . I am able to click on fill in the blank tab without switching into the frame. So, why can't we add text in text area without switching? – Khushboo Aug 12 '14 at 09:10
  • Right click, Inspect Element, Right click and Copy Xpath, this xpath is not working. – Khushboo Aug 12 '14 at 09:24

1 Answers1

0

A useful Plugin is the firebug plugin, with this plugin you could inspect your website and copy a working xpath. I use this Plugin too. But if you want to have a more stabile xpath you have to build a xpath structure. You should use a structure which is unique for this element. Maybe a combination of multiple attributes.

Pascal
  • 74
  • 8