[Celenium] I don't know how to choose the link.

Asked 2 years ago, Updated 2 years ago, 44 views

from selenium import webdriver
path= "C:/Users\KIM/Downloads/chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get('https://komyojikyozo.web.fc2.com')
# Find a frame 
iframes = driver.find_elements_by_css_selector('frame')
for iframe in iframes:
    print(iframe.get_attribute('name'))
# Switch to frame
driver.switch_to.frame('menu')

#? Why doesn't the page come out when I switched frames?
element = driver.find_element_by_css_selector("a").get_attribute('href')

I'd like to click on that link as a selenium. I keep getting errors whether it's a grammar mistakes. How do I select href = "javascript_:void(0)" for tag a?

<a href="javascript_:void(0)" onclick="changeVis('dnskvmenu', 'dnskvtree')">「戒蘊篇」</a>

selenium python

2022-09-20 15:03

1 Answers

Do it like this.


a = 'body > table:nth-child(5) > tbody > tr:nth-child(2) > td:nth-child(1) > div > a'
element = driver.find_element_by_css_selector(a).get_attribute('href')


2022-09-20 15:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.