-1

I have a python script that uses selenium to go to the bottom of a web page, www.tradingview.com/screener. Once it's at the bottom of the page, I need to use an auto it script I made to click on a save button. Both the python script and the auto it script are working separately but I'm trying to call the auto it script from the python script. I thought it might be as simple as putting an include line in the python script to call the auto it script but it's not working. Does anyone know how to accomplish this? I'll put both scripts below. Thanks

Python Script to go to the bottom of the web page.

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException


url = 'http://www.tradingview.com/screener'
driver = webdriver.Firefox()
driver.get(url)

try:

    selector = '.js-field-total.tv-screener-table__field-value--total'
    condition = EC.visibility_of_element_located((By.CSS_SELECTOR, selector))
    matches = WebDriverWait(driver, 10).until(condition)
    matches = int(matches.text.split()[0])

except (TimeoutException, Exception):
    print ('Problem finding matches, setting default...')
    matches = 4895 # Set default

# The page loads 150 rows at a time; divide matches by
# 150 to determine the number of times we need to scroll;
# add 5 extra scrolls just to be sure
num_loops = int(matches / 150 + 5)

for _ in range(num_loops):

    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    sleep(1) # Pause briefly to allow loading time

Auto It script to click a save button.

; Script Start - Add your code below here

ShellExecute("https://www.tradingview.com/screener")

#include <Vince.au3>
Sleep(4000)
Send("{END 20}") ; Presses the DEL key 4 times
MouseClick($MOUSE_CLICK_LEFT, 2460, 46, 1)
Sleep(7000)
Send("{ENTER}") ; Presses the DEL key 4 times
J R
  • 185
  • 1
  • 1
  • 12
  • Alichino is correct, but you can do everything that AutoIt script does in your python script using python and selenium – Ywapom Jul 17 '18 at 15:14
  • sending keys and clicking is supported by the webdriver. So you can do something like driver.move_to_location(2460, 46, 1).click() and driver.send_keys(Key.ENTER) type stuff. http://selenium-python.readthedocs.io/api.html – Ywapom Jul 18 '18 at 16:09

1 Answers1

0

I normally fired up my AutoIT scripts with:

subprocess.Popen(<path to AutoIT .exe file>)

Don't forget about import subprocess

Alichino
  • 1,668
  • 2
  • 16
  • 25
  • It's telling me I didn't declare Mouseclick. How do I do that? – J R Jul 18 '18 at 10:01
  • You don't need to simulate all that with AutoIT. Use Python/Selenium to navigate to the page, then to the Save button, then click it. Only use AutoIT on the explorer window -- where Windows wants you to specify the save location. – Alichino Jul 18 '18 at 11:58
  • Yes but I don't know how to navigate to the Firefox addons save button. – J R Jul 18 '18 at 14:09