情景是登錄到Facebook帳戶,然後註銷。我嘗試使用xpath className和id。但每次它顯示錯誤爲ElementNotfound或元素不可見。之後,我使用SELENIUM IDE對其進行了檢查,並獲得了此LOGOUT鏈接的xpath。但錯誤依然存在。請幫助我。selenium Facebook登錄和註銷的測試用例
public class FacebookLogin {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
Thread.sleep(2000);
WebElement username = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.id("pass"));
WebElement Login = driver.findElement(By.id("u_0_v"));
username.sendKeys("[email protected]");
password.sendKeys("mypassword");
Login.click();
Thread.sleep(2000);
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement navigationclick = driver.findElement(By.id("logoutMenu"));
WebElement logout = driver.findElement(By.xpath("//div[@id='u_d_1']/div/div/div/div/div/ul/li[12]/a/span/span"));
navigationclick.click();
if(logout.isEnabled() && logout.isDisplayed()) {
logout.click();
}
else {
System.out.println("Element not found");
}
}
}
HTML代碼註銷 註銷
'.implicitlyWait()'實際上並沒有等待...它只是設置默認的等待。請參閱[的文檔(https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html)。 – JeffC
請不要忘記將它標記爲答案。 – JeffC
在xpath中有靜態值可能並不總是有效。在這種情況下,它使用像'// li [12]'。您可能需要一些更通用但唯一的位置標識符 – Rao