I have a list with a few boxers. I have created a function that will use selenium to open a particular web page, and then type in the name of a given boxer in my list on an autocomplete box. I then click on the first name that appears and then click on a view more (href). I continue clicking on view more until I get to the bottom of the page
I then read all the text with list of fights the boxer has fought and append to a dataframe column. I have tested this code with one boxer and know that it definitely works up until this point.
I then click on a download stats button for each fight in the list of fights I have collected and get text from the form that pops up. I then append all this information to another column.
This is the code I have written:
boxer_list = ['Deontay Wilder','Tyson Fury','Andy Ruiz']
def get_boxers(boxers):
page_link = 'http://beta.compuboxdata.com/fighter'
chromedriver = 'C:\\Users\\User\\Downloads\\chromedriver'
cdriver = webdriver.Chrome(chromedriver)
cdriver.maximize_window()
cdriver.get(page_link)
wait = WebDriverWait(cdriver,10)
wait.until(EC.visibility_of_element_located((By.ID,'s2id_autogen1'))).send_keys(str(boxers))
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'select2-result-label'))).click()
while True:
try:
element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'view_more')))
element.click()
except TimeoutException:
break
fighters = cdriver.find_elements_by_xpath("//div[@class='row row-bottom-margin-5']/div[2]")
cols = ['fighters', 'stats']
fight_data = pd.DataFrame(columns = cols)
for fighter in fighters:
fight_data.append({'fighters':fighter.text},ignore_index=True)
cdriver.find_element_by_xpath("//a[contains(@onclick,'get_fight_report')]").click()
punches = cdriver.find_elements_by_xpath("//div[@class='modal-content']")
for punch in punches:
fight_data.append({'stats':punch.text},ignore_index=True)
cdriver.refresh()
return fight_data
boxing_dict = {boxer.replace(' ',''):pd.DataFrame([get_boxers(boxer)]) for boxer in boxer_list}
However when I run my function I get the error message:
ElementClickInterceptedException Traceback (most recent call last)
<ipython-input-204-1e27dbb96927> in <module>
35 cdriver.refresh()
36 return fight_data
---> 37 boxing_dict = {boxer.replace(' ',''):pd.DataFrame([get_boxers(boxer)]) for boxer in boxer_list}
..............
ElementClickInterceptedException: Message: element click intercepted: Element <a class="view_more" href="javascript:void(0);" onclick="_search('0')">...</a> is not clickable at point (274, 774). Other element would receive the click: <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">...</div>
(Session info: chrome=78.0.3904.108)
So from what I am gathering the code works up until this point
for fighter in fighters:
fight_data.append({'fighters':fighter.text},ignore_index=True)
I cannot, while looping through each of the fights in the list, click on the download button and get the punch stats from the pop up. This appears to be were the error message is coming from (I assume)
UPDATE:
I have tried updating my for loop to to wait before clicking on the view download button for each fight in my loop
for fighter in fighters:
fight_data.append({'fighters':fighter.text},ignore_index=True)
elem = wait.until(EC.element_to_be_clickable((By.XPATH,"//a[contains(@onclick,'get_fight_report')]")))
elem.click()
punches = cdriver.find_elements_by_xpath("//div[@class='modal-content']")
for punch in punches:
fight_data.append({'stats':punch.text},ignore_index=True)
Running this with a hardcoded key in send_keys() still returns an empty dataframe