#python #python_2x #selenium
При воспроизведении теста, экспортированного из Selenium производится такая ошибка:
ERROR: test_fdefd (main.Fdefd)
Traceback (most recent call last):
File "C:\Users\user\Desktop\Tests\fdefd.py", line 12, in setUp
self.driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line
80, in __init__
self.binary, timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py",
line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py",
line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py",
line 108, in _wait_until_connectable
% (self.profile.path))
WebDriverException: Message: Can't load the profile. Profile Dir: c:\users\user\appdata\local\temp\tmpeywhqv
If you specified a log_file in the FirefoxBinary constructor, check it for details.
Ran 1 test in 93.277s
FAILED (errors=1)
Код программы:
# -*- coding: utf-8 -*-
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
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class Fdefd(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://bugscatcher.net/"
self.verificationErrors = []
self.accept_next_alert = True
def test_fdefd(self):
driver = self.driver
driver.get("http://automated-testing.info/t/selenium-podbiraem-lokatory/2269")
driver.find_element_by_id("site-logo").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: 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__":
unittest.main()
Ответы
Ответ 1
Код который генерирует Selenium IDE, надо править, но вы сможете это не раньше чем поймете что и где в коде происходит. Не буду гадать что вы пытались проверить своим тестом, но например найти в яндексе слово "Selenium" , а потом проверить что в результатах есть их сайт можно следующим способом. (Python 3.x). Если нужны будут пояснения по коду, можете обращаться. import unittest from selenium import webdriver class testClass(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.get("https://www.yandex.ru") self.driver.implicitly_wait(10) def test_log_in(self): element_input = self.driver.find_element_by_xpath('//input[@id="text"]') element_input.send_keys('Selenium') element_button_find = self.driver.find_element_by_xpath('//div[@class="search2__button"]/button') element_button_find.click() try: self.driver.find_element_by_link_text('Selenium - Web Browser Automation') except Exception as err: print('Some error:', err) def tearDown(self): print("Close browser") self.driver.close() if __name__ == "__main__": unittest.main()
Комментариев нет:
Отправить комментарий