セットアップ付:
は、ここに私のコードです。以下の.py
スクリプトでは、アンカーがうまく見つかりました。
index.htmlを、
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe name="mainframe" src="iframe1.html"></iframe>
</body>
</html>
iframe1.html、
<html>
<head></head>
<body>
<iframe name="childframe" src="iframe2.html"></frame>
</body>
</html>
iframe2.html、
<html>
<head></head>
<body>
<a href="/a">AGENT-WIN3E64 </a>
<a href="/b">b</a>
<a href="/c">c</a>
<a href="/d">d</a>
<a href="/e">e</a>
</body>
</html>
test.py
from splinter import Browser
browser = Browser('firefox', wait_time=10)
browser.visit("http://localhost:8000/index.html")
# get mainframe
with browser.get_iframe('mainframe') as mainframe:
# get childframe
with mainframe.get_iframe('childframe') as childframe:
anchorList = childframe.find_by_tag('a')
for e in anchorList:
if e['text'] == u'AGENT-WIN3E64 ': #unicode string comparison
print "found anchor"
e.click()
break;
の
この出力、
found anchor
しかし、あなたはまた、XPathを使用して直接アンカーを見つけることができることに注意し、
anchor = childframe.find_by_xpath("//a[text() = 'AGENT-WIN3E64 ']")