與安裝下面我試圖重新您所描述的情況。下面的.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 ']")