<iframe id="iframe10737" _color="main_gray" src="cn.edu.sufe.ext.stuAct.protal.queryActByType.flow?dlid=10737&color=main_gray" width="100%" height="450px" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes">
#document
<html class="js cssanimations">
<head>...</head>
<body style="background-color:#fff;" marginwidth="0" marginheight="0">
<ul data-am-widget="gallery" class="am-gallery am-avg-sm-2 am-avg-md-5 am-avg-lg-4 am-gallery-bordered am-no-layout" data-am-gallery="{ }">
::before
<li>
<a href="/ext/cn.edu.sufe.ext.stuAct.actDetail.flow?id=28da6cbbe5d44b7a9074c26a0d1f22a0" target="_blank">
<div style="padding:10px 0px;">
<img src="cn.edu.sufe.common.util.FileDownload.flow?fileid=af55af7c42cd498c904d7a092945382b" style="width:170px;height:127px;" width="170px" height="127px">
<h3 class="am-gallery-title">Outdoor Sport Association</h3>
<div class="am-gallery-desc">start time:</div>
<div class="am-gallery-desc">end time:2018-01-17</div>
</div>
</a>
</li>
::after
</ul>
</body>
</iframe>
我需要找到该元素并单击它:
<h3 class="am-gallery-title">Outdoor Sport Association</h3>
我已经尝试了很多,但仍未解决。
driver.find_element_by_css_selector('h3[class="am-gallery-title"]').click()
driver.find_element_by_class_name("am-gallery-title").click()
driver.find_element_by_xpath('//*[contains(text(),"Outdoor Sport Association")]').click()
driver.find_element_by_partial_link_text('Outdoor Sport Association').click()
driver.find_element_by_css_selector('h3.Outdoor Sport Association').click()
driver.find_element_by_css_selector('/body/ul/li/a/div/h3').click()
driver.find_element_by_xpath('//*[@class="js cssanimations"]/body/div[2]/div/h1/a').click()
这些方法根本不起作用。它们都说:
NoSuchElementException:没有这样的元素:无法找到 元件:{...}
。 有人能给我一些建议吗?感谢!!!
答案 0 :(得分:2)
h3
元素位于iframe
内。为了能够处理它,您需要先切换到iframe
:
driver.switch_to_frame('iframe10737')
driver.find_element_by_xpath('//h3[text()="Outdoor Sport Association"]')