无法通过Selenium Python代码通过Chrome浏览器登录

时间:2013-11-01 10:40:27

标签: google-chrome selenium-webdriver

我必须打开一个网站,我必须提供登录ID和密码。 我在Selenium中使用Python为webdrivers编写代码,但我无法登录,因为脚本无法填写密码框,其中用户名框由脚本填充。

下面是代码。相同的代码适用于IE和Firefox。

from selenium import webdriver
from selenium import webdriver
import selenium.webdriver.chrome.webdriver
from selenium.webdriver import Chrome as Browser
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re




    class LoginAa(unittest.TestCase):
        def setUp(self):

            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(30)
            self.base_url = "https://hostname.com"
            self.verificationErrors = []
            self.accept_next_alert = True

        def test_login_aa(self):
            driver = self.driver
            driver.get("https://hostname.com")
            time.sleep(5)
            self.assertEqual("User Login", driver.title)
            #driver.find_element_by_id("IDToken1").clear()
            driver.find_element_by_id("IDToken1").send_keys("abcd")
            time.sleep(5)

            driver.find_element_by_id("IDToken2").clear()
            driver.find_element_by_id("IDToken2").send_keys("qwerty")
            #driver.find_element_by_css_selector("input[type='password']").click()

0 个答案:

没有答案