selenium测试用例,用于Facebook登录和注销 [英] selenium Test case for facebook login and logout
本文介绍了selenium测试用例,用于Facebook登录和注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
方案是登录到Facebook帐户,然后注销.我尝试使用xpath className和id.但是每次它显示错误为ElementNotfound或元素不可见.后来,我使用SELENIUM IDE对其进行了检查,并获得了用于登出链接的xpath.但是错误仍然存在.请帮助我.
Scenario is to Login to facebook account and then logout. I tried using xpath className and id. But everytime it shows error as ElementNotfound or element not visible. Later I Checked it using SELENIUM IDE and got this xpath for the LOGOUT link. But still the error persists. Kindly help me.
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("myusername@xyz.com");
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代码 登出
HTML CODE FOR LOG OUT Log Out
推荐答案
此代码解决了从Facebook注销的问题:
This code solved the issue for Logout from Facebook:
driver.findElement(By.xpath("//div[@id='userNavigationLabel']")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//li[12]/a/span/span")).click();
这篇关于selenium测试用例,用于Facebook登录和注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文