登录flipkart应用程序后无法识别问候语链接



以下代码中预期的操作:

  • 用户成功登录
  • 用户移动到网站的右上角,点击问候链接"嗨……!"

步骤2未发生,因为WebDriver未识别问候语超链接。我做错了什么?

WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://flipkart.com");
driver.findElement(By.xpath(".//*[@id='container']/div/div/header/div[2]/div/div[1]/ul/li[8]/a")).click();
driver.findElement(By.xpath("//input[@class='fk-input login-form-input user-email']")).sendKeys("emailid");
driver.findElement(By.xpath("//input[@class='fk-input login-form-input user-pwd']")).sendKeys("password");      
driver.findElement(By.xpath(".//*[@id='fk-mainbody-id']/div/div/div[1]/div/div[4]/div[7]/input")).click();
driver.findElement(By.linkText("Greeting _link")).click();                              

错误消息:

线程"main"org.openqa.selenium.NoSuchElementException中出现异常:无法定位元素:{"方法":"链接文本","选择器":"Greeting_link"}

HTML是:

<li class="_2sYLhZ _2mEF1S" data-reactid="26"> 
    <a class="_1AHrFc _2k0gmP" data-reactid="27" href="#">Hi Neha!</a> 
    <ul class="_1u5ANM" data-reactid="28">

正如我在登录后看到的那样,没有看起来像Hi username..!的链接,但根据你的评论,我观察到你在谈论My account链接,这在我的情况下是可见的,我只是在重写你的代码,它将从登录到注销自动化,如下所示:-

driver.get("http://www.flipkart.com/");
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Log In"))).click(); //it will click on login button
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input.user-email"))).sendKeys("user name"); //it will fill user name
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input.user-pwd"))).sendKeys('password'); //it will fill password
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.login-btn"))).click(); //it will click on login button
WebElement myAccount = wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("My Account")));
Mouse mouse = ((HasInputDevices)driver).getMouse();
mouse.mouseMove(((Locatable)hoverElement).getCoordinates()); //it will perform mouse over on My Account link, if in your case it show as 'Hi Neha!' you can replace it.
wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Log Out"))).click(); //it will click on logout click after mouse over

希望能有所帮助…:)

最新更新