lundi 2 juillet 2018

Why Am Getting Unable To Locate Element Error?

I Have Divided The Xpath into 4 Parts Because in Xpath only one Row Value Changes That is /tr[2] Like that 3,4,5 upto the Path Ends.

public class NewTest {
  @Test
  public void f() throws InterruptedException 
  {

            System.setProperty("webdriver.chrome.driver",
                    "F:\\New folder\\chromedriver.exe");

        WebDriver driver = new ChromeDriver();

        driver.get("http://xxxxxxxxxxx/index.aspx");


        driver.manage().window().maximize();


        WebElement ee= driver.findElement(By.id("ddlstore"));
        Select s11 = new Select(ee);
        s11.selectByVisibleText("xxxxxx");

        String s1 = "/html[1]/body[1]/form[1]/div[5]/center[1]";

        String s2 = "/div[1]/table[1]/tbody[1]/tr[";

        String s3 ="]";

        String s4 = "/td[11]/input[1]";

        for(int i=2;i<=99;i++)
        {
            String finalXpath= s1+s2+i+s3+s4;

            driver.findElement(By.xpath(finalXpath)).click();

            Thread.sleep(3000);

            try {
                WebElement e1 = driver.findElement(By
                        .xpath("//p[@id='skipcount']"));
                System.out.println(e1.getText());

                WebElement e2 = driver.findElement(By.xpath("/html/body/div[1]/div/div"));
                WebElement e3 = driver.findElement(By.xpath("/html/body/div[1]/div/div/div[3]/button[2]"));
                Actions a1 = new Actions(driver);
                a1.moveToElement(e2).click(e3).build().perform();

            } catch (Exception e) {
                System.out.println("Can't Click on The Element ");
            }
    }

The Element is Not Clicking it is Showing an Error , Unable to Locate Element,Xpath

Html Code For The First Xpath Divided into String :

<input type="submit" name="CustomPaging_GridView$ctl02$ff" value="SKIP" onclick="product_skip(this);" id="CustomPaging_GridView_ff_0" class="button2" data-id="12691247570" data-id1="36025">

Html Code For Xpath Which is in Try/Catch Block:

<div class="modal-footer">
                    <span id="prcid" style="display:none;">processing...</span>
                    <button type="button" id="skipok" onclick="skipoverall(this)" class="btn btn-primary" data-id="12691247570" data-id1="36025">Ok</button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                </div>

Ps : Actually The Doubt is, I Need To Click an Skip Button Which has an Same Xpath For All Button and Each Time When i Click Skip Button an Popup Will Appear in That i Need To Click The Cancel Button

Aucun commentaire:

Enregistrer un commentaire