2
<a class="menu-item js-add-to-basket pizzaAddDefault js-change-ingredients js-add-pizza-to-basket" id="ph-add-to-basket-61504822" data-id="61504822" upsell-id="" href="/amrest-pizzahut/products#category/pizza" style="height: auto;">
            <div class="ph-order-on-preview">
                <button class="btn btn--primary">Zamów online</button>
            </div>
            <div id="ph-add-to-basket-61504822" class="box-counter ph-product-in-basket hidden" data-id="61504822">
                <span class="ph-products-in-basket-number">0</span>
            </div>
            <div class="menu-item__content">
                <h5>
                    <!-- 
                            <div class="ph-menu-favorite js-favourite" sec:authorize="!isAnonymous()">
                                <img th:src="@{/images/favourite-unchecked.png}" class="unchecked" alt="Nie ulubiona" />
                            </div>
                     -->
                    VEGE DELUX
                </h5>
                <p>
                    37,99 PLN
                </p>
                <p class="menu-item__description"></p>
            </div>
            <div class="menu-item__image">
                <img src="https://ocs-pl.oktawave.com/v1/AUTH_876e5729-f8dd-45dd-908f-35d8bb716177/amrest-web-ordering/GRD4/GRD4590/Smaki%20Premium/Pizza_vege_medium_450x450.png" alt="VEGE DELUX">
            </div>
        </a>

Above there's code from my site, i need to move mouse button on this class, and next press 'zamów online' button

I have following locators for this item:

    @FindBy (css="#ph-add-to-basket-61504822") WebElement firstpizza;
    @FindBy (css="#ph-add-to-basket-61504822 .ph-order-on-preview button") WebElement pizzabutton;

and functions

public void clickPizzaBasket() {
    Actions action = new Actions(driver);
    action.moveToElement(firstpizza);
    System.out.print("moved");
    pizzabutton.click();
}

executing this function i get org.openqa.selenium.ElementNotVisibleException: element not visible on pizzabutton.click() line

In which way i should access to 'zamów online' buttons?

enter image description here

3 Answers 3

1

How about this one -

 @FindBy (id="ph-add-to-basket-61504822") WebElement firstpizza;
 @FindBy (xpath="//button[contains(text(), 'online')]") WebElement pizzabutton;

    public void clickPizzaBasket() {
        Actions action = new Actions(driver);
        action.moveToElement(firstpizza).perform(); 
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(pizzabutton));
        pizzabutton.click();
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

@FindBy (css="#ph-add-to-basket-61504822") WebElement firstpizza;
@FindBy (css="#ph-add-to-basket-61504822 > div.ph-order-on-preview > button") WebElement pizzabutton;

public void clickPizzaBasket() {
    Thread.sleep(2000); // add pause
    Actions action = new Actions(driver);
    action.moveToElement(firstpizza).perform(); // you forgot to perform the action
    System.out.print("moved");
    Thread.sleep(2000); // add pause
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(pizzabutton));
    pizzabutton.click();
}

10 Comments

On your new locator with xpath: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"span[contains(., 'Zamów online')]"}.If i added perform to my action - nothing changes, still org.openqa.selenium.ElementNotVisibleException: element not visible
Are you sure that firstpizza id is static?
Yes, this locator is static
Does it print 'moved' and then throw exception?
Try my xpath one more time, I had an error. The xpath is updated
|
0

On page there're more than 1 element with id in @FindBy (css=1 and css=2 versions) Its working if I use List instead of WebElement

    @FindBy (css=".pizza.show h5") List <WebElement> namesOfPizzas;
    @FindBy (css=".pizza.show button") List <WebElement> pizzaOrderButtons;

and function:

    public void clickOrderFirstPizza() throws InterruptedException {
    Actions action = new Actions(driver);
    Thread.sleep(500);
    action.moveToElement(namesOfPizzas.get(0)).build().perform();       
    System.out.print("moved");
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(pizzaOrderButtons.get(0)));
    pizzaOrderButtons.get(0).click();
}

Thanks for help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.