Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python-Authorization-selenium_Python_Selenium_Selenium Webdriver - Fatal编程技术网

python-Authorization-selenium

python-Authorization-selenium,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我是python新手。想登录我的帐户吗 我的代码是: driver = webdriver.Firefox() session = requests.Session() url = "http://tterminal.info/" response = session.post(url) # <div class="auth"> authForm = driver.find_element_by_class_name("auth") # <div class="login"&

我是python新手。想登录我的帐户吗 我的代码是:

driver = webdriver.Firefox()
session = requests.Session()

url = "http://tterminal.info/"
response = session.post(url)
# <div class="auth">
authForm = driver.find_element_by_class_name("auth")
# <div class="login">
loginForm = authForm.find_element_by_class_name("login")
# Enter login
login = loginForm.find_element_by_name("login")
login.clear()
login.send_keys("mylogin")
# Enter pass
pswd = loginForm.find_element_by_name("pass")
pswd.send_keys("mypassword")
# Click login
loginForm.find_element_by_class_name("submit").click()
driver=webdriver.Firefox()
会话=请求。会话()
url=”http://tterminal.info/"
response=session.post(url)
# 
authForm=驱动程序。通过类名称(“auth”)查找元素
# 
loginForm=authForm。通过类名称(“登录”)查找元素
#输入登录名
login=loginForm。通过名称(“login”)查找元素
login.clear()
登录。发送密钥(“mylogin”)
#进入通行证
pswd=loginForm.find\u element\u by\u name(“pass”)
pswd.发送密钥(“我的密码”)
#单击登录
loginForm.按类名称(“提交”)查找元素。单击()
但它使SME无法找到元素。auth 我的错在哪里?

使用Selenium时,您不必使用
请求。Session()
模块,您的代码块可以优化如下:

from selenium import webdriver

driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
url = "http://tterminal.info"
driver.get(url)
login = driver.find_element_by_css_selector("form[name='login'] input.text[name='login']")
login.clear()
login.send_keys("mylogin")
pswd = driver.find_element_by_css_selector("form[name='login'] input.text[name='pass']")
pswd.send_keys("mypassword")
driver.find_element_by_css_selector("form[name='login'] input.submit").click()
为什么会有一个“≠" 在python代码中?