Issue
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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.