2

I have c# webdriver configured for my Visual Studio 2010. I want to clcik on a button "Install" from the Iframe. I am writing c# code to click on Install button from this IFrame.

Here is the HTML code...

<html>
<head></head>
<body>
<"pt1:pt2:mvtiframe" class="gradbg af_inlineFrame p_AFFlow" frameborder="0"   onload="AdfDhtmlInlineFramePeer.__iframeLoadHandler(event)" src="some url" style="width:700px; height:360px" _adfloaded="1">
<html>
<tr>
<td style="text-align: left; height: 35px" colspan="3">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<p>
<a class="imageButton" onclick="OnNextButtonClick()" target="_blank" href="http://google.com/abc.asp">
<span>Install</span>
</a>
</p>
</td>
</tr>
</html>
</iframe>
</body>
</html>

I am trying with below code to click on "Install" button. But does not work. It says could not locate the element.

FirefoxDriver driver = new FirefoxDriver();
driver.SwitchTo().Frame(0);
driver.FindElement(By.Name("Install")).Click();

Tried with Xpath but i don't get the Xpath for Install button which is part of the IFrame.

1 Answer 1

1

The problem here is that the "Name" of the element is not "Install" Install is the text for the button.

I would try some Xpath like this: "//a[@class='imageButton']"

driver.FindElement(By.Xpath("//a[@class='imageButton']")).Click();

If that's your page source, you should be able to find the element using that class. This is all assuming that your SwitchTo().Frame is working as expected.

Also, if possible, I would really recommend putting a name or ID on that iFrame instead of using index. It will be more reliable in the long run, if the page changes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.