在Java中使用Selenium登录到Facebook

时间:2019-05-25 16:25:02

标签: java selenium selenium-chromedriver

我尝试使用Selenium库登录Facebook,但是出现一些问题。输入凭据并单击登录按钮后,出现错误消息:

Cookies Required
Cookies are not enabled on your browser. Please enable cookies in your browser preferences to continue.

我已经在互联网上寻找答案,所以我尝试使用driver.manage().getCookies();并得到相同的结果。

这是我的代码:

System.setProperty("webdriver.chrome.driver", DRIVERLOCATION);
WebDriver driver = new ChromeDriver();
driver.manage().getCookies();


driver.get("https://www.facebook.com");

driver.findElement(By.id("email")).sendKeys(USERNAME);
driver.findElement(By.id("pass")).sendKeys(PASSWORD);
driver.findElement(By.xpath("//input[starts-with(@id, 'u_0_')][@value='Log In']")).click();

1 个答案:

答案 0 :(得分:0)

在我说的问题中,我知道我尝试访问www.facebook.com,但在实际项目中,我正在访问个人资料。

当您转到https://www.facebook.comerror occurs when your going to a profile or if you have second authentication activated.

时,效果很好