程序无法识别按钮的定位器

时间:2019-01-29 13:46:33

标签: java selenium selenium-webdriver cucumber google-chrome-devtools

您好,我的程序无法识别按钮的定位器。但它确实可以识别此网站中的其他按钮。     我已经尝试了一些webdriver元素功能,但是没有一个起作用。     该程序是求职面试的一部分,所以我需要尽快得到答案。

应该点击此按钮的功能是 public void i_click_on_chosen_extra()

here you can have a clear look on the page and the button         包stepDefinitions;

    import java.io.IOException;
    import java.nio.file.Paths;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;

    import cucumber.api.java.After; 
    import cucumber.api.java.Before;
    import cucumber.api.java.en.Given;
    import cucumber.api.java.en.Then;
    import cucumber.api.java.en.When;



    public class consumeSteps {

    WebDriver driver;


    @Before
    public void setup() throws IOException {
        System.setProperty("webdriver.chrome.driver", 
    Paths.get(System.getProperty("user.dir")).toRealPath() +  
    "\\src\\test\\java\\drivers\\chromedriver.exe");
        this.driver = new ChromeDriver();
        this.driver.manage().window().maximize();
        this.driver.manage().timeouts().pageLoadTimeout(120, 
    TimeUnit.SECONDS);
    }


    @After() 
    public void tearDown() {
        this.driver.manage().deleteAllCookies();
        this.driver.quit();
    }


    @Given("^I access pizzahut\\.co\\.il$")
    public void i_access_pizzahut_co_il() throws Throwable {
        driver.get("https://pizzahut.co.il/");

    }

    @When("^I click on sales section button$")
    public void i_click_on_sales_section_button() throws Throwable {
        String path = "//*[@id=\"off-canvas- 
    content\"]/main/div[1]/home-page/div/div[2]/div/div/div/div[1]/a";
        WebDriverWait wait = new WebDriverWait(driver, 5);


  //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(path)));
        driver.findElement(By.xpath("//*[@id=\"off-canvas- 
   content\"]/main/div[1]/home-page/div/div[2]/div/div/div/div[1]/a")).click();


    }

    @When("^I click on add family non gluten pizza button$")
    public void i_click_on_add_family_non_gluten_pizza_button() throws 
    Throwable {
        WebDriverWait wait = new WebDriverWait(driver, 5);

        String path = "//*[@id=\"off-canvas- 
   content\"]/main/div[1]/div/div/div[1]/ui-view/products- 
    page/div/ul/li[3]/main-product/article/div/div/button";

   wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(path)));
       driver.findElement(By.xpath(path)).click();

    }

    @When("^I click on add button$")
    public void i_click_on_add_button() throws Throwable {
    WebDriverWait wait = new WebDriverWait(driver, 5);

        String path = "//*[@id=\"off-canvas- 
   content\"]/main/div[1]/div/div/div/div[1]/order-products- 
   page/div/ul/li/main-product/article/div/div/button";

   wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(path)));
       driver.findElement(By.xpath(path)).click();

    }

    @When("^I click on chosen extra$")
    public void i_click_on_chosen_extra() throws Throwable {
    WebDriverWait wait = new WebDriverWait(driver, 5);
        String olivesPath = "//*[@id=\"off-canvas- 
   content\"]/main/div[1]/div/div/div/div[1]/order-pizza-toppings- 
   page/div/div[2]/toppings- 
   select/div/carousel/div/div/div/div[1]/div[1]/topping/div";
        String olivesForWholePizzaPath = "//*[@id=\"topping-10- 
   full\"]";
        String pepersPath = "//*[@id=\"off-canvas- 
    content\"]/main/div[1]/div/div/div/div[1]/order-pizza-toppings- 
   page/div/div[2]/toppings- 
   select/div/carousel/div/div/div/div[1]/div[2]/topping/div";
        String pepersForWholePizzaPath = "//*[@id=\"topping-11- 
   full\"]";
     wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(olivesPath)));  
        driver.findElement(By.xpath(olivesPath)).click();
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("topping-10-full")));
        driver.findElement(By.xpath(olivesForWholePizzaPath)).click();
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("topping-11-full")));
        driver.findElement(By.xpath(pepersPath)).click();         


 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(pepersForWhol 
   ePizzaPath)));
        driver.findElement(By.xpath(pepersForWholePizzaPath)).click();



    }



    @When("^I click on choose and next button$")
    public void i_click_on_choose_and_next_button() throws Throwable {
        WebDriverWait wait = new WebDriverWait(driver, 5);

        String path = "//*[@id=\"off-canvas- 
      content\"]/main/div[1]/div/div/div/div[1]/order-pizza-toppings- 
   page/div/div[3]/div/div[2]/button";


     wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(path)));
       driver.findElement(By.xpath(path)).click();



    }

    @When("^I click on continue for payment allert button$")
    public void i_click_on_continue_for_payment_allert_button() throws 
    Throwable {
        WebDriverWait wait = new WebDriverWait(driver, 5);

        String path = "/html/body/div[7]/article/a";

   wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(path)));
       driver.findElement(By.xpath(path)).click();



    }

    @When("^I click on continue for payment button$")
    public void i_click_on_continue_for_payment_button() throws Throwable {
        WebDriverWait wait = new WebDriverWait(driver, 5);

        String path = "//*[@id=\"off-canvas- 
   content\"]/main/div[1]/div/order-cart-page/div/div/div[2]/div/order- 
   summary/div/div[4]/button";;

   wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(path)));
       driver.findElement(By.xpath(path)).click();  


    }

    @Then("^I should successfully be moved to the payment form$")
    public void i_should_successfully_be_moved_to_the_payment_form() throws 
    Throwable {
        // Write code here that turns the phrase above into concrete 
    actions

    }



    }

0 个答案:

没有答案