Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium:成功登录后无法获取任何元素_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java Selenium:成功登录后无法获取任何元素

Java Selenium:成功登录后无法获取任何元素,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我使用selenium登录网站。但我无法在新页面中获取任何元素 代码如下: public class SeleniumProcessor { public WebDriver driver; public SeleniumProcessor() { this.driver = new FirefoxDriver(); } public void openUrl(String url) { driver.get(url); } public void login(Strin

我使用selenium登录网站。但我无法在新页面中获取任何元素

代码如下:

public class SeleniumProcessor {
public WebDriver driver;


public SeleniumProcessor() {
    this.driver = new FirefoxDriver();
}

public void openUrl(String url) {
    driver.get(url);
}

public void login(String userName, String password) {
    WebElement userNameTxt = driver.findElement(By.id("username"));
    WebElement passwordTxt = driver.findElement(By.id("password"));
    userNameTxt.sendKeys(userName);
    passwordTxt.sendKeys(password);
    passwordTxt.sendKeys(Keys.RETURN);
}

public static void main(String[] args) throws InterruptedException {
    SeleniumProcessor login = new SeleniumProcessor();
    login.openUrl("https://launch.stellar.org/#/login");
    login.login("myusername", "mypassword");
    // login success but after that when I execute findElement function is always throw Exception like this 
线程“main”org.openqa.selenium.InvalidSelectorException中的异常:给定的选择器btn btn default STERAR button ng绑定无效或未生成WebElement。发生以下错误: InvalidSelectorError:不允许使用复合类名


我还尝试使用显式和隐式等待,。。。但不起作用,即使打印getCurrentURL()也始终为“”。有人知道这个问题的潜在原因或解决方案吗?

如果您写的是,您的登录成功了。你怎么知道的? 我没有stellar.org的帐户,但如果getCurrentUrl仍然提供“”,那么我建议您登录失败。 您是否尝试过
驱动程序.getPageSource()

您还会收到一个InvalidSelectorException。我猜这个例外试图解释它自己。您的选择器错误(可能是忘记了右括号),或者选择器没有生成WebElement。
如果您无法帮助处理异常,则可能会将导致异常的选择器发送给target。

这是一个基于AngularJS的应用程序,查找元素可能会有点麻烦,除非使用量角器,否则最终会出现长XPath和CSS选择器

这是你的课程中的一个片段,经过重构后为我工作。 我注意到你说你在使用显式等待,它确实对我有用。。。 我的建议是,在应用程序实现自动化之前,手动仔细地研究应用程序的行为

 public class AutoTest{

public static WebDriver autoDriver;

public AutoTest(){

    autoDriver = new FirefoxDriver();
    autoDriver.get("https://launch.stellar.org/#/login");

}

public void login(String username, String password) throws InterruptedException{

    autoDriver.findElement(By.id("username")).sendKeys(username);
    autoDriver.findElement(By.id("password")).sendKeys(password);
    Thread.sleep(1000);
    autoDriver.findElement(By.xpath("//button[.='Log in']")).click();


}

public void faceBookStellar() throws InterruptedException{

    WebElement facebookButon = new WebDriverWait(autoDriver, 10)
    .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[.='Receive your first stellars on us!']")));
    facebookButon.click();


}

public void quiteBrowser(){

    autoDriver.close();
    autoDriver.quit();
}

public static void main(String[]args) throws InterruptedException{

    AutoTest testObject = new AutoTest();
    testObject.login("autoStellarTester", "password");
    testObject.faceBookStellar();

}

}

因为当我运行project时,firefox被打开,我可以看到它登录成功。而当您手动登录时,当前的url是什么?也许你的代码比你的浏览器快。您是否尝试过等待一个指标,即firefox已准备好登录过程?比如等待“注销”按钮?首先感谢您的解决方案,这是成功的。但我仍然不明白我错在哪里,为什么。我使用:WebElement btn=(new-WebDriverWait(login.driver,15)).until(new-ExpectedCondition(){@Override-public-WebElement-apply(WebDriver d){return d.findElement(By.className(“btn-btn-default-stellar-button-ng-binding”);});btn.sendKeys(key.RETURN);我需要一个帮助,在那里我可以学习By.xpath中参数的语法?另外,你在评论中写的是流畅的等待