所以我只是想创建一个代码来通过 gmail 进行导航并自动执行某些任务。我成功地自动登录到 GMail,但是登录后当我尝试检索页面源代码时,我不断遇到此错误代码。
错误代码
org.openqa.selenium.WebDriverException: Error: Permission denied to access property "document" (WARNING: The server did not provide any stacktrace information)
Java 代码
String pageLink = "https://accounts.google.com/ServiceLogin?service=mail#identifier";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(pageLink);
WebElement userName = (new WebDriverWait(driver, 10)).until(ExpectedConditions.visibilityOfElementLocated(By.id("Email")));
userName.sendKeys("myusername");
driver.findElement(By.id("next")).click();
Thread.sleep(2 * 5000);
WebElement passWord = (new WebDriverWait(driver, 10)).until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
passWord.sendKeys("mypassword");
driver.findElement(By.id("signIn")).click();
System.out.println("Logged In!");
Thread.sleep(2 * 5000);
pageCode = driver.getPageSource();
注意:我使用的是最新版本的 Firefox 和最新版本的 Selenium
PS:我已经针对类似问题提出了 11 多个不同的问题,没有人提供明确的解决方案,而且答案非常模糊。
最佳答案
伙计们,我很久以前就找到了这个问题的解决方案,抱歉忘记发布它,将 mozilladriver 切换到 chromedriver 应该可以解决这个问题。干杯:)
关于java - 访问属性的权限被拒绝 "document",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38820856/