0

I am attempting to scrape a page where a list of cases is displayed, and each case is a postback link which submits a form, and the response is the same page with a JavaScript popup of the details. I can request any one, but I've been unable to get switch_to.window or switch_to.frame to work. Any tricks on this type of link?

Runnable code snippet

import undetected_chromedriver.v2 as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import sys

'''
Requires chrome
pip install selenium
pip install undetected_chromedriver

'''

driver = uc.Chrome()

txtUsingTestDates = 'Using test dates'
print(txtUsingTestDates.center(20, "="))
dateStart = "08/02/2021"
dateEnd = "08/02/2021"

with driver:
    driver.get('https://publicindex.sccourts.org/abbeville/publicindex/')
    
try:
    formAcceptTerms = driver.find_element(By.XPATH, "//*[@id='form1']")
except:
    print("Didn't find form")
try:
    driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_ButtonAccept']").click()
    print(">>>Accepting terms")
except:
    print("Didn't find button")

### Search form
#Select court
selectorCourts = Select(driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_DropDownListCourtType']"))
selectorCourts.select_by_visible_text('Circuit Court')

#Select case type
selectorCaseType = Select(driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_DropDownListCaseTypes']"))
selectorCaseType.select_by_visible_text('Criminal-Clerk')

#Select date search for filing date
selectorDateSearchType = Select(driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_DropDownListDateFilter']"))
selectorDateSearchType.select_by_visible_text('Case Filed')

#Fill from and to date
textBoxDateFrom = driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_TextBoxDateFrom']")
textBoxDateFrom.send_keys(dateStart)

textBoxDateTo = driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_TextBoxDateTo']")
textBoxDateTo.send_keys(dateEnd)

get_cookies = driver.get_cookies()
print(get_cookies)

#Submit search
driver.find_element(By.XPATH, "//*[@id='ContentPlaceHolder1_ButtonSearch']").click()

#Click each case number

driver.close()


Jason Bellows
  • 339
  • 2
  • 7
  • Did you try [Selenium IDE Chrome Extension](https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd?hl=en) ? You can run a simulation with the extension to figure out the exact frame to switch. – Goh Kok Han Sep 20 '21 at 04:12
  • sometimes JavaScript needs time to update HTML - it can be even few milliseconds - and you may need `time.sleep()` or one of the method described in documentation [Waits](https://selenium-python.readthedocs.io/waits.html) – furas Sep 20 '21 at 07:18
  • I don't see `switch_to.window` or `switch_to.frame` in your code - better show code with `switch_to` which makes problem. – furas Sep 20 '21 at 07:23
  • The difficulty is that on the site, when I click a case it opens to a new window (in fact, if I try to open in a new tab it fails). In Selenium the first click opens to the same window (no added window_handles). How do I emulate the how the click works in a browser? – Jason Bellows Sep 27 '21 at 19:56

0 Answers0