4

テキストボックスを選択し、セレン Web ドライバーを介してテキストを入力しようとしています。html は次のとおりです。

</div><div>
    <input name="mLayout$ctl00$ctl00$6$16$ctl00$Database" type="text" value="Enter database name" maxlength="175" size="26" id="mLayout_ctl00_ctl00_6_16_ctl00_Database" accesskey="s" title="Go search this database" class="InputContent GhostText" onfocus="SearchBoxOnFocus(&#39;mLayout_ctl00_ctl00_6_16_ctl00_Database&#39;);" onkeypress="if(!__TextBoxOnKeyPress(&#39;mLayout$ctl00$ctl00$6$16$ctl00$GoButton&#39;,event.which)) { return false; }" />&nbsp;<input type="image" name="mLayout$ctl00$ctl00$6$16$ctl00$GoButton" id="mLayout_ctl00_ctl00_6_16_ctl00_GoButton" title="Go search database" src="http://images-statcont.westlaw.com/images/go_v602.gif" alt="Go search database" align="absmiddle" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;mLayout$ctl00$ctl00$6$16$ctl00$GoButton&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" style="height:18px;width:21px;border-width:0px;" />
</div><div>

私は次のことを試しました

driver.find_element_by_id("mLayout_ctl00_ctl00_6_16_ctl00_Database")
driver.find_element_by_name("mLayout$ctl00$ctl00$6$16$ctl00$Database")
dbElement = WebDriverWait(driver, 20).until(lambda x : x.find_element_by_id("mLayout_ctl00_ctl00_6_16_ctl00_Database"))

フィールドの $ と _ 文字に何か特別なものはありますか? セレンがこれらの要素を見つけられないのはなぜですか?

4

3 に答える 3

5

解決策: 正しいウィンドウにいることを確認してください。この前のステップで、新しいウィンドウを開くリンクをクリックし、そのウィンドウが自動的にアクティブになると想定していました。

使用可能なウィンドウを確認するには、次を実行します。

driver.window_handles

これはリストを返します。インデックス i を使用して、変更先のウィンドウに注意してください。ウィンドウを変更するには、次を実行します。

driver.switch_to_window(driver.window_handles[i])
于 2012-11-05T22:24:17.903 に答える
0

アイデアは次のとおりです。名前全体で要素を見つけることができない場合は、名前の一部で要素を見つけようとします。だから私はこのアプローチを試してみます:

A に 't' が含まれる要素の属性 A

xpath : //E[contains(@A,'t')]/@A ⌦ {Se: //E[contains(@A,'t')]@A}

css : NA {Se: css=E[A*='t']@A}ここで取られる

だからそれは何か

driver.find_element_by_xpath("input[contains(@name,'ctl00$Database')]@name")

そのようにして、私は通常、自分のロケーターに自信がない場合に検証します: ここに画像の説明を入力

于 2012-10-21T10:05:45.057 に答える
0

2 行目に追加の二重逆コンマがあります。find_element_by_name(""

driver.find_element_by_name(""mLayout$ctl00$ctl00$6$16$ctl00$Database")

に変更します

driver.find_element_by_name("mLayout$ctl00$ctl00$6$16$ctl00$Database")

abt がわからないときはいつでも、次のような単一の逆コンマを使用し$ます_

driver.find_element_by_name('mLayout$ctl00$ctl00$6$16$ctl00$Database')
于 2012-10-20T21:31:08.897 に答える