0

I am able to filter the data with the code below but the Export to Excel does not work. I request your kind assistance on how to improve my snippet below to instruct Python to wait for the data to get fully loaded and then download the excel file to the desired folder.

from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe") driver.get("https://etrakit.friscotexas.gov/Search/permit.aspx") number_option = driver.find_element_by_id("cplMain_btnSearch") number_option.click() delay = 3 try: WebDriverWait(driver, delay).until(EC.presence_of_element_located(driver.find_element_by_id("cplMain_btnSearch"))) print "Page is ready!" except TimeoutException: print "Loading took too much time!" search_button = driver.find_element_by_id("cplMain_btnExportToExcel") search_button.click() options.add_argument("download.default_directory=C:\Users\Patrick\Desktop\Programming\R Files") driver = webdriver.Chrome(chrome_options=options) driver.close() 

The Error:

Traceback (most recent call last): File "C:\Users\Patrick\Desktop\Programming\aspxscraping.py", line 14, in <module> WebDriverWait(driver, delay).until(EC.presence_of_element_located(driver.find_element_by_id("cplMain_btnSearch"))) File "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until value = method(self._driver) File "C:\Python27\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 63, in __call__ return _find_element(driver, self.locator) File "C:\Python27\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 328, in _find_element return driver.find_element(*by) TypeError: find_element() argument after * must be a sequence, not WebElement 

2 Answers 2

1

Try to replace this

 WebDriverWait(driver, delay).until(EC.presence_of_element_located(driver.find_element_by_id("cplMain_btnSearch")) 

with this

from selenium.webdriver.common.by import By WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, "cplMain_btnSearch"))) 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Anderson, that works for the code. Now it shows an error for Search.Button Traceback (most recent call last): File "C:\Users\aqureshi\Desktop\Programming\aspxscraping.py", line 22, in <module> search_button.click()
Add full exception log to your question and HTML code for search button
1

Your problem is here:

EC.presence_of_element_located(driver.find_element_by_id("cplMain_btnSearch")) 

The point of the wait is to not try finding the element yourself, because it might not be there yet! It so happens that you found it in this case and the error is complaining about your use of presence_of_element_located. Here's what you need to do:

EC.presence_of_element_located((By.ID, "cplMain_btnSearch")) 

See the docs: http://selenium-python.readthedocs.io/waits.html#explicit-waits

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.