ajeet rai
ajeet rai

Reputation: 1

Getting exception: Unable to locate element

I am trying to write a script to automate login and logout for site www.flipkart.com. But my script is failing and giving exception: Unable to locate element: {"method":"link text","selector":"Logout"} I am not able to figure out what is the issue. Can anyone tell what is the issue with my locator. Below is my code:

Actions builder = new Actions(driver);
System.out.print("log1");
WebElement element = driver.findElement(By.xpath(".//*[@id='fk-mainhead-id']/div[1]/div/div[2]/div[1]/ul/li[6]/a"));
System.out.print("log2");
Action action = builder.moveToElement(element).build();
action.perform();
System.out.print("log3");
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS); 
 driver.findElement(By.linkText("Logout")).click();
}

Upvotes: 0

Views: 717

Answers (1)

ddavison
ddavison

Reputation: 29062

You're in luck.. recently, i had helped an individual with logging in and out of flipkart. Here was the script:

@Config(url="http://flipkart.com", browser=Browser.FIREFOX)
public class TestFlipKart extends Conductor {
    @Test
    public void testLoginLogout() {
        String username = "<username>";
        String password = "<password>";

        click(By.cssSelector("a[href*='/login']"))
        .setText(By.cssSelector("input[name='email']"), username)
        .setText(By.cssSelector("input[name='password']"), password)
        .click(By.cssSelector("input[type='submit'][value='Login']"))

        .validatePresent(By.cssSelector("li.greeting-link > a"))

        .hoverOver(By.cssSelector("li.greeting-link > a"))

        .click(By.cssSelector("ul.account-dropdown a[href*='/logout']"))

        // should be logged out now.
        .validatePresent(By.cssSelector("a[href*='/login']"));
    }
}

mind you, this is using the Conductor framework. You can translate the CSS selectors I had in there to your script.

Upvotes: 1

Related Questions