Reputation: 23
<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>
I need to find the element and click it:
<h3 class="am-gallery-title">Outdoor Sport Association</h3>
I have try a lot, but it still unsolved.
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()
Those methods don't work at all.Its all say:
NoSuchElementException: no such element: Unable to locate element:{...}
. Could anyone give me some suggestions? Thanks!!!
Upvotes: 2
Views: 61
Reputation: 52665
h3
element is located inside an iframe
. To be able to handle it, you need to switch to that iframe
first:
driver.switch_to_frame('iframe10737')
driver.find_element_by_xpath('//h3[text()="Outdoor Sport Association"]')
Upvotes: 2