简体   繁体   中英

Element Click Selenium Not Finding Button to Click

For the url below, I am trying to click the "1-50" button (which has its own xpath) and then the "51-100," "101-150," etc. buttons (which all share a 2nd xpath), but my code does not seem to be able to click on the button. Anybody able to figure this out? Cheers!

import pandas as pd
import time
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()

url = 'www.sec.gov/securities/files/year/'

page = driver.get(url)
time.sleep(2)

df_appended = []

df = pd.read_html(driver.page_source)[0]
df_appended.append(df)
    
time.sleep(2)
driver.find_element_by_xpath('//[@id="ctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592_updatePanelctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592"]/table[2]/tbody/tr/td/a/img').click
time.sleep(2)

for i in range(1,3):
    df = pd.read_html(driver.page_source)[0]
    df_appended.append(df)
    driver.find_element_by_xpath('//*[@id="ctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592_updatePanelctl00_m_g_00806bcd_0028_4082_9797_52f6f350e592"]/table[2]/tbody/tr/td/a[3]/img').click()
    time.sleep(1)
    
df_appended

Runs fine if you used the a tag.

driver.find_element_by_xpath('//table[2]/tbody/tr/td/a').click()
time.sleep(2)

for i in range(1,3):
    df = pd.read_html(driver.page_source)[0]
    df_appended.append(df)
    driver.find_element_by_xpath('//table[2]/tbody/tr/td/a[3]').click()
    time.sleep(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM