无法点击网站上的几个项目

时间:2016-10-19 10:09:10

标签: java selenium-webdriver automation

我试图自动化的网站是投注网站,我有一个自动化马匹投注的场景。

我正在使用带有Java的selenium 3.0

从网站上我可以参加赛马但无法选择明天并选择比赛。我尝试使用xpath,类和其他方法,但无法单击这些按钮。

网站是 https://www.williamhill.com.au/

1步。转到上面的网址 2.从左上角选择赛马或导航到网址(https://www.williamhill.com.au/racing?event=horseracing) 3.点击明天我无法做到这一点 4.从表格中选择特定种族(也不能这样)

package automationFramework;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class horseRacing {

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

        String exePath = "D:\\chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", exePath);
        WebDriver driver = new ChromeDriver();

        //Launch the Online Store Website
        driver.get("https://www.williamhill.com.au/");
        Thread.sleep(5);
        driver.manage().window().maximize();
        String Title = driver.getTitle();
        System.out.println(Title);
        driver.findElement(By.className("MenuItem_text_N8V")).click();

        Thread.sleep(25);

       // driver.findElement(By.className("RaceGrid_raceTile_imG RaceGrid_raceDisabled_Q0m")).click();
        driver.findElement(By.xpath("//*[@id='app']/div/div[4]/div/div/div/div[2]/div[1]/div/div[2]/div[2]/div[2]")).click();




        // Print a Log In message to the screen
        System.out.println("Successfully opened the website www.Store.Demoqa.com");

        //Wait for 5 Sec
        Thread.sleep(5);

        // Close the driver
       // driver.quit();        


    }

}

1 个答案:

答案 0 :(得分:0)

我试图点击" TOMORROW"并成功了。

package test;

import org.openqa.selenium.By;
import org.junit.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class NavigateToAUrl {

    @Test
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.williamhill.com.au/racing?event=horseracing");

        driver.findElement(By.xpath(".//*[@id='app']/div/div[4]/div/div/div/div[2]/div[1]/div/div[2]/div[2]/div[2]")).click();

    }
}

您的代码driver.findElement(By.xpath("//*[@id='app']/div/div[4]/div/div/div/div[2]/div[1]/div/div[2]/div[2]/div[2]")).click(); 中缺少点(。) (在// * [@ id~)

之前