'Python script stops after I run a function
I recently started using python and wanted to use it in a project and so far I've gotten:
def jlogin():
botcheckstatus = input("Have you completed the \"Are You Human\" check yet? (Y): ")
if botcheckstatus == "Y" or botcheckstatus == "y":
temp = chrome.find_element_by_id("userid")
temp.send_keys(username)
temp.send_keys(Keys.ENTER)
sleep(1)
temp = chrome.find_element_by_id("pass")
temp.send_keys(password)
temp.send_keys(Keys.ENTER)
jlogin()
print("wont work")
What I dont understand is why pyhton wont run the print command at the end when it runs I assume that I am not using the def fuction right. Any help would be appreciated.
Solution 1:[1]
The reason why the last print didn't work is because jlogin() has an error.
I fixed your coding a little bit.
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
def jlogin():
username = "id"
password = "pw"
botcheckstatus = input("Have you completed the \"Are You Human\" check yet? (Y): ")
if botcheckstatus == "Y" or botcheckstatus == "y":
driver = webdriver.Chrome("./chromedriver") #chromedriver pathway
chrome = driver.get("https://example.com")
temp = chrome.find_element_by_id("userid")
temp.send_keys(username)
temp.send_keys(Keys.ENTER)
time.sleep(1)
temp = chrome.find_element_by_id("pass")
temp.send_keys(password)
temp.send_keys(Keys.ENTER)
jlogin()
print("wont work")
Isn't it because you forgot to import it?
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
I hope it's the answer you want. :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | colin_koko |
