简体   繁体   中英

driver.get(sys.argv[1]) working fine on a PC and not on the other (sys.argv[1], IndexError: list index out of range error)

Title says it all.

Both are PC, both Windows 10, both latest Python (I uninstalled and reinstalled both) and Selenium.

So what am I missing here ? I open a CMD on both PCs and type the same thing :

myscript.py "myurlargument"

It's the very same script that I execute from my Dropbox on one PC on which it works fine, and on the other on which it fails with this error.

The first line of the script :

from selenium import webdriver
import sys

driver = webdriver.Chrome(executable_path="chromedriver")
driver.get(sys.argv[1])

Thanks for your help.

sys.argv[0] represents the script name, and sys.argv[1:] represents the parameters passed. If you know this part and are passing the proper arguments, then try error handling.

Either by putting your code in Try and Except block and putting it to sys.argv[0] or any other values, when it goes index out of range.

My best best would be to debug it, and see what parameters are being passed in both the system and cure your error handling from there, OR by creating a rule or function to use the arguments if provided else use the default Argument.

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