Reputation: 39
So for a few days i've been trying to make selenium to click Link1
but without success, i tried many different ways to do it but all of them failed
Here is a list of things i tried and what errors i got.
Unable to locate element: Link1: find_element_by_link_text('Link1').click()
Unable to locate element: //a[contains(@href,'#') and contains(.,'Link1')]:
find_element_by_xpath("//a[contains(@href,'#') and contains(.,'Link1')]").click()
AttributeError: 'list' object has no attribute 'click': find_elements_by_xpath("//a[contains(text(), 'Link1')]").click()
HTML CODE:
<frameset rows="*,1" frameborder="no" framespacing="0" border="0" >
<frame src="/something" name="center" marginheight="0" marginwidth="0" noresize="">
<iframe id="something"></iframe>
<div id="content-area">
<div id="something">
<div class="Content">
<div class="pageNavigation" id="pageNavigation">
<ul>
<li>
<a href="#" onclick="javascriptcode1">Link1</a>
</li>
<li class="last">
<a href="#" onclick="javascriptcode2">Link2</a>
</li>
</ul>
</div>
</div>
</div>
</div>
My Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
def selenium():
driver = webdriver.Firefox()
driver.get("https://something.com")
time.sleep(3.5)
#driver.find_element_by_link_text('Link1').click()
#driver.find_elements_by_xpath("//a[contains(text(), 'Link1')]").click()
#driver.find_elements_by_xpath("//a[contains(text(), 'Link1')]").click()
selenium()
Edit: I just noticed that the link is inside an <frameset>
and another <frame>
, and after that another <iframe>
which closes immediately s Also :
<frameset>
-> <frame>
-> <iframe></iframe>
-> Link1
Upvotes: 0
Views: 441
Reputation: 688
driver.switch_to.frame(driver.find_element_by_name(name)) # use any applicable method
driver.find_element_by_link_text('Link1').click()
driver.switch_to.default_content()
Upvotes: 1