PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 15, 2022

[FIXED] How to move Slider in an IFRAME that doesn't have a name/id?

 April 15, 2022     iframe, java, selenium-webdriver     No comments   

Issue

enter image description here I am unable to move the slider in an IFRAME section: https://jqueryui.com/slider/

The IFRAME doesn't have a name or id on this page.

Code:

public class MovingSlider {
    public static void main(String[] args) 
    {
        WebDriverManager.chromedriver().setup();
        WebDriver driver = new ChromeDriver();
        driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
        driver.get("https://jqueryui.com/slider/");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        driver.switchTo().frame(1);
        WebElement slider = driver.findElement(By.xpath("//div[@id = 'slider']/span"));
        new Actions(driver).dragAndDropBy(slider, 400,0).click();
    }
}

Solution

The issue is dom contains only one frame whose index is "0" and you tried to switch to index "1" frame which actually didn't exist.

Following is the code snippet that works for you.

WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
driver.get("https://jqueryui.com/slider/");
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
Integer size = driver.findElements(By.tagName("iframe")).size();
System.out.println("Total iFrame is " + size);
driver.switchTo().frame(0);
WebElement slider = driver.findElement(By.xpath("//div[@id = 'slider']/span"));
// WebElement slider = driver.findElement(By.cssSelector("#slider > span"));
new Actions(driver).dragAndDropBy(slider, 400, 0).build().perform();


Answered By - Muhammad Farooq
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing