программа не может распознать локатор кнопки - PullRequest
0 голосов
/ 29 января 2019

Привет, моя программа не может распознать локатор кнопки.но он распознал другие кнопки на этом веб-сайте.Я попробовал несколько функций элемента webdriver, но ни одна не работала.эта программа является частью собеседования, поэтому мне нужен ответ как можно скорее.

функция, которая должна нажать на эту кнопку, является общедоступной. void i_click_on_chosen_extra ()

здесьВы можете четко видеть страницу и кнопку package 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

    }



    }
...