Уведомления

Группа в Telegram: @pythonsu

#1 Окт. 7, 2013 23:13:44

Alexey1992
Зарегистрирован: 2013-10-07
Сообщения: 3
Репутация: +  0  -
Профиль   Отправить e-mail  

Selenium+Python проблема

Привет! Есть скрипт, который выполняет авторизацию на сайте и далее проходя по паре ссылок добавляет на него инфу. Проблема в том, что после авторизации скрипт сыпется с ошибкой:

ERROR: test_i_s (__main__.IS)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\Алексей\Documents\IS.py", line 27, in test_i_s
driver.find_element_by_xpath("//div[@id='zz3_TopNavigationMenuV4']/div/ul/li[2]/a/span/span").click()
File "C:\Python33\lib\site-packages\selenium-2.35.0-py3.3.egg\selenium\webdriver\remote\webdriver.py", line 222, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Python33\lib\site-packages\selenium-2.35.0-py3.3.egg\selenium\webdriver\remote\webdriver.py", line 680, in find_element
{'using': by, 'value': value})['value']
File "C:\Python33\lib\site-packages\selenium-2.35.0-py3.3.egg\selenium\webdriver\remote\webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "C:\Python33\lib\site-packages\selenium-2.35.0-py3.3.egg\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: '\'[JavaScript Error: "a is null" {file: "file:///c:/users/cd86~1/appdata/local/temp/tmpqanx6z/extensions/fxdriver@googlecode.com/components/command_processor.js" line: 8172}]\' when calling method: [nsICommandProcessor::execute]' 
----------------------------------------------------------------------
Ran 1 test in 24.535s
FAILED (errors=1)
Traceback (most recent call last):
File "C:\Users\Алексей\Documents\IS.py", line 114, in <module>
unittest.main()
File "C:\Python33\lib\unittest\main.py", line 125, in __init__
self.runTests()
File "C:\Python33\lib\unittest\main.py", line 267, in runTests
sys.exit(not self.result.wasSuccessful())
SystemExit: True



Кусок кода приведен ниже:

from selenium import webdriver
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 IS(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://nsi.gosuslugi.ru/"
self.verificationErrors = []
self.accept_next_alert = True
def test_i_s(self):
driver = self.driver
driver.get(self.base_url + "/_layouts/NsiInfrastructure/WelcomePage.aspx")
driver.find_element_by_id("ctl00_IdWelcome_ExplicitLogin").click()
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("146-")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("lexo")
driver.find_element_by_xpath(u"(//button[@value='Войти'])[4]").click()
time.sleep(7)
driver.find_element_by_xpath("//div[@id='zz3_TopNavigationMenuV4']/div/ul/li[2]/a/span/span").click()
driver.find_element_by_css_selector(u"td[title=\"ОГВ\"]").click()
driver.find_element_by_id("ctl00_m_FormWP_View_ViewDataBtn").click()
-----
-----
------
----
 def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException: return False
        return True
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException: return False
        return True
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
    try:
        unittest.main()
    except SystemExit as inst:
        if inst.args[0] is True: # raised by sys.exit(True) when tests failed
            raise



все валится после успешного выполнения
driver.find_element_by_xpath(u"(//button)“).click()
и попытки выполнить :
driver.find_element_by_xpath(”//div/div/ul/li/a/span/span").click()


Если запускать скрипт без авторизации, то он успешно выполняется. Но соединив все вместе валится с такой ошибкой. С python-ом знаком совсем недавно, буду рад помощи) спасибо!

Отредактировано Alexey1992 (Окт. 8, 2013 07:12:18)

Офлайн

#2 Окт. 8, 2013 09:49:17

malya
От:
Зарегистрирован: 2012-01-11
Сообщения: 49
Репутация: +  1  -
Профиль   Отправить e-mail  

Selenium+Python проблема

У меня валится по таймауту на кнопке войти.

Даже поменял это:

driver.find_element_by_xpath(u"(//button[@value='Войти'])[4]").click()
на это:
driver.find_element_by_xpath("//div[@id='content']/div/div[2]/div/div/div/div[1]/div[4]/button").click()

Всеравно.



Офлайн

#3 Окт. 8, 2013 09:51:58

Alexey1992
Зарегистрирован: 2013-10-07
Сообщения: 3
Репутация: +  0  -
Профиль   Отправить e-mail  

Selenium+Python проблема

просто я указал неверные логин пароль) так то заходит а дальше не хочет

Офлайн

#4 Окт. 8, 2013 15:40:10

Alexey1992
Зарегистрирован: 2013-10-07
Сообщения: 3
Репутация: +  0  -
Профиль   Отправить e-mail  

Selenium+Python проблема

Может у кого была подобная проблема? логин/пароль, понятное дело, дать не могу для проверки

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version