以下代码中预期的操作:
第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:无法找到元素:{“method”:“link text”,“selector”:“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">
答案 0 :(得分:0)
正如我在登录后看到的那样,没有看起来像Hi username..!
的链接,但根据您的评论,我发现您正在谈论My account
链接,这在我的案例中是可见的,我&#39 ; m只是重写你的代码,这将从登录到注销自动化,如下所示: -
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
希望它有所帮助.. :)