2

html code:

<iframe title="javascript:''" src="PageName.aspx" _events="[object Object]">
    <htlml>
        <head>
            <body>
                 <form name="FormName">
                      <div>
                          <span>
                               <input name="ButtonName>

My question: how can I find the element with name "ButtonName"? My current code in C#

//To find the iframe
IWebElement Object = driver.FindElement(By.XPath("XPath to the iframe");   //works
//To switch to and set focus to the iframe
driver.SwitchTo().Frame(Object);  //works

//To find element with name "ButtonName"
IWebElement Button = driver.FindElement(By.Name("ButtonName"));  //error: cannot find the element 

Any help is appreciated.

4

2 に答える 2

0

昨日、たような質問に答えました。要素を IWebElement 変数に入れましたが、使用しませんでした。

user197586 が指摘したように実行します。

driver.FindElement(By.Name("ButtonName"));

または、要素変数を使用して何かを行います。

IWebElement Button = driver.FindElement(By.Name("ButtonName"));
Button.DoSomething();

要素が表示されることを確認するだけの場合は、それを IWebElement 変数に割り当てる必要はありません。後で要素を使用する場合は、実際に使用するようにしてください。

于 2013-10-22T20:32:20.887 に答える