0

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();
}
1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.