Reputation: 25
I have been stuck on trying to click the href="javascript:void(0);" on a page.
My problem is that I am not able to select this using selenium, and my end goal is to click on one. The page is fully loaded, and this is what all the links on the page have as the href.
my code is this:
a = soup.find_all('a')
for names in a:
try:
print (names['href'])
if names['href'] == "javascript:void(0);":
print "IM IN HUR"
names.click()
break
except:
continue
But the "name.click()" statement never works.I have not found any way to click on javascript:void(0). Any help would be much appreciated.
Upvotes: 1
Views: 4780
Reputation: 5137
You have to use Selenium WebDriver to interact with web browser. Your variable names
is an object of Beautiful Soup which is a Python package for parsing HTML/XML, it cannot interact with web browser. Try code below:
aElements = browser.find_elements_by_tag_name("a")
for name in aElements:
if(name.get_attribute("href") is not None and "javascript:void" in name.get_attribute("href")):
print("IM IN HUR")
name.click()
break
Upvotes: 3