当前位置: 首页 > 知识库问答 >
问题:

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

帅博简
2023-03-14

我使用硒登录网站 https://launch.stellar.org/#/login。但我无法在新页面中获取任何元素。

这里是代码:

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 stellar-按钮ng-绑定无效或不会导致WebElement。发生以下错误:InvalidSelectorError:不允许复合类名……

我也尝试使用显式和隐式等待,…但是不起作用,甚至打印getMONtURL()总是“https://launch.stellar.org/#/login”。有人知道这个问题的潜在原因或解决方案吗?

共有2个答案

吕高雅
2023-03-14

你写,你的登录成功了。你怎么知道的?我没有stellar.org的帐户,但是如果getMONtUrl仍然提供“https://launch.stellar.org/#/login”,那么我建议你的登录失败。你试过driver.getPageSource()吗?

此外,您还会收到一个无效选择器异常。我猜异常试图解释自己。要么你的选择器是错误的(可能是一个被遗忘的封闭括号),要么选择器没有产生WebElement。如果您不想帮助解决异常,则可能是针对性地发布导致异常的选择器。

郦何平
2023-03-14

这是一个基于AngularJS的应用程序,查找元素可能有点麻烦,除非使用量角器,否则您最终会使用Long 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();

}

}

 类似资料:
  • 问题内容: 嗨,您已经用yeoman,grunt和bower创建了一个angularJS应用程序。我已经为应用程序启用了html5Mode。及其工作。但是,当我刷新页面(localhost:9000 / login)时,它说 这是应用程序结构 这是我的 app.js 路由 这是我的Gruntfile.js 我已经解决了这个问题。根据已接受的答案,我将Gruntfile.js更改为以下内容。 但是刷

  • 我试图了解spring-web安全性。为此,我创建了一个具有登录页面和两个不同用户的Web应用程序。 管理员 LoginController类处理三种类型的URL。 网状物xml 在Spring安全中,我使用“admin/”限制所有网址 在提供管理员用户名和密码后,应用程序将打开管理员页面。 现在,当我单击“ManageUser”时,我希望应用程序将我带到ManageUser页面。但上面写着“拒绝

  • 问题内容: 我尝试了这个:当isSessionValid getDetails直接否则else facebook.authorize,然后在onActivityResult中获取getDetails 当我的系统上安装了Facebook应用程序时,此方法工作正常。但是,如果未安装,我将获得一个Web视图以输入facebook凭据,并在logcat中显示登录成功,但是没有调用getDetails块。

  • 问题内容: 我想要在spring成功注册后自动登录:我有一个受保护的页面,需要登录才能访问它们,我要在注册后跳过登录页面并进行自动登录,以便用户可以看到受保护的页面有我吗?我正在使用spring 3.0,spring security 3.0.2,该怎么做? 问题答案: 可以通过以下方式(半伪代码)通过spring安全性完成此操作: 更新:仅包含注册后如何创建会话

  • MvcConfig方法如下所示:

  • 我正在用android编程。当我使用(LoginActivity)成功登录时,下一步是加载MainActivity,这个MainActivity是一个导航抽屉活动,但我遇到了这个错误: 致命异常:主进程:com.example.administrador.vicon,PID:32149java.lang.运行时异常:无法启动活动ComponentInfo{com.example.administr