I have same Skip types kept for 99 products. When I need to that, it will bring a popup. In the popup I need to the Cancel . Each time when I click on the Skip buton it will give a popup like this.

popup

So I used this . it is up to a point of time and throwing an error.

My code is

package Backendsite;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;

public class SkipTest {
    @Test
    public void f() throws InterruptedException {
        System.setProperty("webdriver.chrome.driver",
                "F:\New folder\chromedriver.exe");

        // Setting To Open Incoginoto Window
        ChromeOptions options = new ChromeOptions();
        options.addArguments("-incognito");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        WebDriver chromedriver = new ChromeDriver(capabilities);

        chromedriver.manage().window().maximize();

        // Opening The WebSite
        chromedriver.get("xxxxxxxxxxx");

        chromedriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        Pomsite p1 = PageFactory.initElements(chromedriver, Pomsite.class);

        Select s1 = new Select(p1.getE1());
        s1.selectByVisibleText("xxxxxxxxxxxx");


        Thread.sleep(3000);

        List<WebElement> elements = chromedriver.findElements(By.xpath("//input[contains(@id, 'CustomPaging_GridView_gv_edit1_')]"));


        Thread.sleep(2000);

        for (Iterator<WebElement> iterator = elements.iterator(); iterator.hasNext();)
        {


            WebElement webElement = (WebElement) iterator.next();

            Thread.sleep(2000);

            webElement.click();

            Thread.sleep(2000);

            chromedriver.findElement(By.xpath("//button[text()='Cancel']")).click();
        }  

The Exception error is ,

org.openqa.selenium.ElementNotVisibleException: element not visible

PS: Sometimes I see Stale Element Reference Error.



Source link https://sqa.stackexchange.com/questions/34480/why-my-code-is-not-working-when-i-click-on-the-same-button-for--

LEAVE A REPLY

Please enter your comment!
Please enter your name here