私はChrome webdriverでPython/Seleniumを使用していますが、別の<td>
の内容に基づいて<td>
からURLを取得しようとしています。私のマークアップは次のようになります。jQueryとスクリプトの実行者と十分に簡単ですJSからPython Seleniumへの文字列の受け渡し
<div class="targetclass">
<tr>
<td><a href="[email protected]">emailval2</a></td>
<td><a href="[email protected]">emailval</a></td>
</tr>
</div>
:私はwebdriverを一緒に使用するために返されたHREFを保存しようとすると、しかし
with open('jquery-3.2.1.min.js', 'r') as jquery_js:
jquery = jquery_js.read() #read the jquery from a file
driver.execute_script(jquery) # activate the jquery lib
driver.execute_script("$('div.targetclass a[href$=\"[email protected]\"]').parents(\"tr\").find(\"a:first\").attr('href')")
、私は次の結果を持っている:
をaurlval = driver.execute_script("$('div.targetclass a[href$=\"[email protected]\"]').parents(\"tr\").find(\"a:first\").attr('href')")
print (aurlval)
返される値は
None
です
ターゲットURL([email protected]
)を保存して、Webdriverで操作できるようにするにはどうすればよいですか?
私は.parent行でロードブロッキングを打っています.Seleniumでは.parentが異なる方法で使用されていると思います。これを実現するにはxpathが必要なようです。 – Marcatectura