0

I am stuck with a problem in automating pages having an iframe,

http://jqueryui.com/draggable/

Scenario here is to Drag and drop element present INSIDE the iframe element which thus cannot be recognized by WebDriver

aquaraga
  • 4,138
  • 23
  • 29
Chirag Pandit
  • 43
  • 4
  • 8
  • Is your issue that you're not able to simulate a drag and drop through WebDriver? Or that the iframe has no id or class? In any case, please make the question a little clear. – aquaraga Dec 20 '13 at 04:58
  • xpath or CSS selectors will easily work, even if no id or class property, so that shouldn't be much of an issue. But you'll need to show us the source to get any help on that. The other branch of the question is a duplicate of: http://stackoverflow.com/questions/14210051/how-to-automate-drag-drop-functionality-using-selenium-web-driver – t0mppa Dec 20 '13 at 05:52
  • Post the code you have tried so far and error you see if any. – Akbar Dec 20 '13 at 06:34

2 Answers2

2

Option 1: Use CSS Selector or XPath

WebElement iframe = driver.findElement(By.cssSelector(".demo-frame"));
// alternative locators:
// XPath: .//iframe[@class='demo-frame']
// use src attribute
// Css Selector: iframe[src*='demos/draggable']
// XPath: .//iframe[contains(@src, 'demos/draggable')]

driver.switchTo().frame(iframe);

WebElement draggable = driver.findElement(By.id("draggable"));
// do your drag, where do you want to drop?

Option 2: Use index (not recommended)

driver.switchTo().frame(0);
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
  • Thank you soo much for that answer :) And how do you discover the XPath of the Element? I dont know what is XPath please guide me accordingly, I always do is rightclick in Sel-IDE and click any element to get the XPath but in a genaral case how do we find the XPath? – Chirag Pandit Dec 20 '13 at 06:57
0

for xpath you have to install firebug and firepath through addons in your Firefox browser.After installing, firebug will be shown on your Navigation bar. you have to just click on that and you can find firepath overthere which will provide you xpath css path etc. with help of inspector.

shrutika
  • 3
  • 1
  • 5