0

Below is the site, http://www.mortgagecalculator.org/

click on Get Today's Best Mortgage Rates & you will get one popup window,which is there in frame. select purchase radio button and click on search button.

Here is my code. I am unable to select the radio button with my code. need suggestion. Thanks

driver.get("http://www.mortgagecalculator.org/");
driver.findElement(By.xpath(".//*[@id='calc']/form/section/section[2]/div/div/div[1]/div/div/div[3]/div[1]/div[1]/div[4]/a/strong/font")).click();
Thread.sleep(3000);
driver.switchTo().frame("brbodxlxcs");
Thread.sleep(4000);
System.out.println("***");
driver.findElement(By.xpath(".//*[@id='brTabbedRateTable']/div[1]/form[2]/div/div[3]/div[1]/ul/li[1]/input")).click();
driver.findElement(By.xpath(".//*[@id='brTabbedRateTable']/div[1]/form[2]/div/div[3]/div[2]/ul/li[8]/a")).click();
Thread.sleep(2000);
Shoaib Shaikh
  • 343
  • 7
  • 22
snigdha
  • 26
  • 4

4 Answers4

0

There is browser security related to iframes.
You cannot get access to the elements in an iframe like you can other parts of your page.

Others have struggled with this also: Selecting an element in iFrame jQuery

Community
  • 1
  • 1
raddevus
  • 8,142
  • 7
  • 66
  • 87
0

Change driver.switchTo().frame("brbodxlxcs"); to match something like driver.switchTo().frame(driver.findElement(By.tagName("iframe[title='Fill Quote']")));

rt2800
  • 3,045
  • 2
  • 19
  • 26
0

The frame that you are referring to brbodxlxcs , seems like id of this frame is dynamically changing.

Try this, its working for me

driver.get("http://www.mortgagecalculator.org/");
driver.findElement(By.xpath(".//*[@id='calc']/form/section/section[2]/div/div/div[1]/div/div/div[3]/div[1]/div[1]/div[4]/a/strong/font")).click();
Thread.sleep(8000);
List<WebElement> frames = driver.findElements(By.cssSelector("iframe"));
System.out.println(frames.size());
Iterator<WebElement> it = frames.iterator();
while(it.hasNext())
{
      WebElement temp = it.next();
      System.out.println(temp.getAttribute("id"));
 }

This gives me all the available frames, in this case its 5. Then i tried for different frames available one by one & finally got this to work by

driver.switchTo().frame(2);

also i modified xpath for radio button like

 .//*[@id='brTabbedRateTable']//form[@name='mtgSearchForm']//input[@name='loantype' and @value='purchase']

& Search button like this,

.//*[@id='brTabbedRateTable']//form[@name='mtgSearchForm']//a[text()='Search' and @class='br-submit']

I hope it helps !!

Shoaib Shaikh
  • 343
  • 7
  • 22
  • Thanks but still im unable to select the purchase radio button. here is the exception org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (241, 660). Other element would receive the click: – snigdha Jul 23 '15 at 05:39
  • **Element is not clickable at point (241, 660)** ?? are you using coordinates to click on the element?? – Shoaib Shaikh Jul 23 '15 at 07:16
0

It looks the problem you are having is that the iFrame id is dynamic and is different every time the page is rendered. There are two iFrames on the page so use an xpath like to one below to find a specific instance:

(//iframe)[2]
CynicalBiker
  • 579
  • 5
  • 14