How to locate an element which is inside the iframe?



  • I'm new to automation testing (I'm using TestNG framework and Java language) I'm having trouble in locating an element which is inside iframe.

    WebElement iframeSwitch= driver.findElement(By.id("configFrame"));
    driver.switchTo().frame(iframeSwitch); System.out.println("Switched");
    driver.findElements(By.xpath("//input[@ng-change='ProcessUpdates(m);']")).clea‌​r();
    driver.findElement(By.xpath("//input[@ng-change='ProcessUpdates(m);']")).sendK‌​eys("Arsenal"); 
    driver.findElement(By.id("SearchAll")).click(); Thread.sleep(15000);
    driver.switchTo().defaultContent(); JavascriptExecutor js=(JavascriptExecutor)driver;
    js.executeScript("javascript:window.scrollBy(0,300)");
    

    The element which i need to perform action is in the iframe itself, so do i need to use the driver.switchTo().defaultContent();

    I tried to find it using the XPath. When I provided the XPath in Selenium IDE, it found the element, but when I wrote the script in TestNG and gave the same Xpath, it returned an exception of unable to locate the element. I'm new to Java as well as to automation. So if someone can provide some hint, it will be great help!



  • Scrolling page using cordinates:

    JavascriptExecutor b = (JavascriptExecutor)driver;
    b.executeScript("scroll(0,400)");
    

    scrolling page to perticular location by using webelement:

        JavascriptExecutor b = (JavascriptExecutor)driver;
        WebElement c = driver.findElement(By.xpath(""));
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        b.executeScript("arguments[0].scrollIntoView(true)",c);
    

    hope this helps!!!



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2