0

I am new to Selenium. I am learning by automating some test scenarios on MakeMyTrip website.

Scenario: Editing the user account created.

Code:(yet to be completed)

public class AccountEdit {

    @Test
    public void AccEdit() 
    {

        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.makemytrip.com/");
        driver.manage().window().maximize();
        driver.findElement(By.id("ssologinlink")).click();
        driver.findElement(By.id("username")).sendKeys("abcd@gmail.com");
        driver.findElement(By.id("password_text")).sendKeys("*****");
        driver.findElement(By.id("login_btn")).click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.findElement(By.id("ssologinlink")).click(); **======> Here I notice the click is not happening to select the My Account or My Profile from the drop down.** 

    }

}   

Kindly let me know how I can take the focus back to the webelement once I login. driver.findElement(By.id("ssologinlink")).click(); works fine the first time but not post the user login.

Saifur
  • 16,081
  • 6
  • 49
  • 73
Rek Sel
  • 21
  • 1
  • 1
  • 2

3 Answers3

1

Thank you for your comments. The element ID had not changed post the login. I had to wait for the user name to appear before I click on the drop down.

Below is the code which worked for me:

public class AccountEdit {

@Test
public void AccEdit() 
{

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.makemytrip.com/");
    driver.manage().window().maximize();
    driver.findElement(By.id("ssologinlink")).click();


    driver.findElement(By.id("username")).sendKeys(""abcd@gmail.com"");
    driver.findElement(By.id("password_text")).sendKeys("*******!");
    driver.findElement(By.id("login_btn")).click();

     WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='ssologinlink']/strong[contains(text(),'user')]")));
     myDynamicElement.click();

}

}

Rek Sel
  • 21
  • 1
  • 1
  • 2
0

Try waiting for the element to be clickable with Expected Conditions of Explicit waits. See the doc here

public class AccountEdit {

    @Test
    public void AccEdit() 
    {

        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.makemytrip.com/");
        driver.manage().window().maximize();
        driver.findElement(By.id("ssologinlink")).click();
        driver.findElement(By.id("username")).sendKeys("abcd@gmail.com");
        driver.findElement(By.id("password_text")).sendKeys("*****");
        driver.findElement(By.id("login_btn")).click();
        //Waiting for the element to be clickable with Explicit wait       
        WebElement myDynamicElement = (new WebDriverWait(driver, 10))
        .until(ExpectedConditions.elementToBeClickable(By.id("ssologinlink")));
        myDynamicElement.click();
    }
}   
Saifur
  • 16,081
  • 6
  • 49
  • 73
-1

Some time element ID gets changed post login(something like dynamic ID).. pls. check the element ID again and update..

Maddy
  • 63
  • 7
  • Use below function if you want to check again again and mulitple elements.. public void waitForElementClickable(WebDriver driver, By locator, Integer timeoutInSeconds){ WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); wait.until(ExpectedConditions.elementToBeClickable(locator)); } – Maddy Jun 18 '15 at 09:21