使用href作为定位器单击锚标记很困难

时间:2015-06-10 09:58:06

标签: java selenium css-selectors type-mismatch

如何在Selenium中找到以下代码行的标识符?

<a href="loginPage" class="loginBtn" data-toggle="modal" data-target="rnr-loginPanel">Login</a>

我试过了:

driver.findElement(By.xpath("//a [contains ( @href = 'loginPage' )]")).click(); 

但它不适合我。

1 个答案:

答案 0 :(得分:1)

xpath中的 contains 关键字存在语法问题。以下应该工作 -

   private void playerHealth() {
        JDialog.setDefaultLookAndFeelDecorated(true);
        if (player.health <= 0) {
            int response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.NO_OPTION) {
                System.exit(0);
        } 
            else if (response == JOptionPane.YES_OPTION) {
                new Game().start();
        } 
            else if (response == JOptionPane.CLOSED_OPTION) {
                System.exit(0);
        }
     }
 }  

此外,更好更简单的方法是

package core;

public class Launcher {

    public static void main(String[] args){
        //Launches new Game
            new Game().start();    
    }    
}