I am using python selenium webdriver in our framework , of late we have been seeing errors like below
(<type 'exceptions.AttributeError'>,
AttributeError("'unicode' object has no attribute 'text'",)
,<traceback object at 0x00000000037D8D48>)
And also we are seeing this error in our product which has unicode charecters in them.Doesnt happen always happens once in 15 times.
Stacktrace:
self.compare_units_test('Singapore')
line 391, in compare_units_test
self.assertTrue(home_page.is_loaded(), Errors.HOMEPAGE_LOGO_ERROR)
File "", line 32, in is_loaded
"Logo did not load results in 10 seconds")
File "\venv\lib\site-packages\pscore\core\support\ps_wait.py", line 20,in until_visible
self._wait_until_visible(locator, timeout, message, True)
File "venv\lib\site-packages\pscore\core\support\ps_wait.py", line 15, in _wait_until_visible
wait.until(EC.visibility_of_element_located(locator), message=message)
File "\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 66, in until
value = method(self._driver)
File "\venv\lib\site- packages\selenium\webdriver\support\expected_conditions.py", line 72, in __call__
return _element_if_visible(_find_element(driver, self.locator))
File \venv\lib\site- packages\selenium\webdriver\support\expected_conditions.py", line 90, in _element_if_visible
return element if element.is_displayed() else False
AttributeError: 'unicode' object has no attribute 'is_displayed'
2015-09-10 15:56:36 - INFO wd_testcase.py:111 in run : Test Runner: Tearing down test: test_compare_units (tests.test.TestFlightsSearch)
2015-09-10 15:56:36 - INFO wd_testcase.py:48 in tearDown : Test Runner: Attempting to teardown.
2015-09-10 15:56:36 - ERROR wd_testcase.py:125 in run : Traceback (most recent call last):
File \venv\lib\site-packages\pscore\core\wd_testcase.py", line 112, in run
self.tearDown()
File "\venv\lib\site-packages\pscore\core\wd_testcase.py", line 49, in tearDown
WebDriverFinalizer.finalize(self.driver, self.has_failed(), self.logger, self.test_context)
File "\venv\lib\site-packages\pscore\core\finalizers.py", line 28, in finalize
WebDriverFinalizer.finalize_skygrid(driver, test_failed, test_context) File "\lib\site-packages\pscore\core\finalizers.py", line 152, in finalize_skygrid
WebDriverFinalizer.finalise_skygrid_driver_failure(driver, test_context)
File "\venv\lib\site-packages\pscore\core\finalizers.py", line 168, in finalise_skygrid_driver_failure
final_url = driver.current_url
File "venv\lib\site- packages\selenium\webdriver\support\event_firing_webdriver.py", line 201, in __getattr__
raise AttributeError(name)AttributeError: current_url
We are using 2.45 version of selenium and 2.7.7 version of python.
When i dug into webdriver source code found this
try:
str = basestring
except NameError:
pass
which specifically addresses the unicode problem which webdriver was running into.
Any ideas what might be causing this? Help would be greatly appreciated
Found the root cause of the problem, it looked like one of the tests was spawning a new browser window and the subsequent tests were using the dialog window instead of the browser window to do selenium commands. At some point one of the tests performed a driver.quit and when the subsequent tests tried to access driver.something they failed since driver was already killed.
Related
title='this is the title'
I want to locate with python/selenium, within a web page, this line:
<input id="subject" name="subject" maxlength="50" value="" class="nude error" type="text">
I use this code with python-selenium (under Debian):
title = driver.find_element_by_id("subject").clear()
title.send_keys(title)
I got the following error:
Traceback (most recent call last):
File "./basic0", line 49, in <module>
titre.send_keys(title)
AttributeError: 'NoneType' object has no attribute 'send_keys'
note:when the script stops because of this error, the mouse cursor is at the right at place within the web page; but I cannot find a way to send_keys to fill in the input
I also tried:
title = driver.find_element_by_xpath("div[contains(text(),'subject')]")
title = driver.find_element_by_xpath("//form[input/#id='subject']")
title = driver.find_element_by_xpath("//form[input[#name='subject']")
but it does not work; furthermore the mouse cursor is not at the right place.
then I tried a later selenium version:
I completly purge python-selenium package under Debian (which is selenium v. 2.53)
then
pip install selenium==3.3.1
This time, when I launch the script it says that geckodriver is missing:
so,
wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux32.tar.gz
tar -xvzf geckodriver-v0.23.0-linux32.tar.gz
chmod 755 geckodriver (I also tried 777)
mv geckodriver /usr/local/bin/ (so it's in my PATH)
now when I launch the script, here is the error message I got:
Traceback (most recent call last):
File "./basic0", line 13, in <module>
driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refuse
firefox window pops-up, and then shutdown when the script stops
You've assigned method call (clear()) which returns None to title variable while you need to define WebElement and call methods subsequently as
title = driver.find_element_by_id("subject")
title.clear()
title.send_keys("title")
if you are able to click in the text box but you are unable to type in there because send_keys is not working and you are in hurry or you want to just click without selecting any element then:
please install this module by typing pip install pyautogui
import pyautogui
#use this line to type something
pyautogui.typewrite('Anything you wanna type')
#use this line to press any key
pyautogui.press("esc")
[here][1] is the list of keys you can press
Note : If you are going to minimize the windows pyautogui will start typing at the place you currently clicking or when the pyautogui.typewite() is executing and you are on other pages it will start typing on the page you are in rather then typing on webpage.
I have code of this
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import time
driver = webdriver.Chrome()
And the error occurs at the last line : driver = webdriver.Chrome()
It says this :
Traceback (most recent call last):
File "/Users/Edison/Desktop/untitled folder/huamai_jacket1.py", line 9, in <module>
driver = webdriver.Chrome()
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__
log_path=service_log_path)
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 42, in __init__
start_error_message="Please see https://sites.google.com/a/chromium.org/chromedriver/home")
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 42, in __init__
self.port = utils.free_port()
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/common/utils.py", line 36, in free_port
free_socket.bind(('0.0.0.0', 0))
File "/Users/Edison/anaconda2/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 49] Can't assign requested address
Exception AttributeError: "'Service' object has no attribute 'log_file'" in <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x1049a93d0>> ignored
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/Edison/Desktop/untitled folder/huamai_jacket1.py"]
[dir: /Users/Edison/Desktop/untitled folder]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
Happens this morning and the thing is right after this happens, sometimes when i access website even like google.com, the ERR_ADDRESS_INVALID page shows up often and i need to keep refreshing to get the page back to the regular site.
Is this because that the driver.Chrome() does not include the PATH of Chromedriver location? I used my script for a week before today though and everything worked perfectly.
Please help :(
So if you do not pass a path as a part of the "webdriver.Chrome('path/to/chromedriver')" is will search along the PATH environment variable to find it. So first thing I would do is verify where my chromedriver is. If it is not in $PATH then you can put it in usr/bin and try running again. Or you can pass the path to your chromedriver executable in the .Chrome().
I am attempting to run a simple program on an Ubuntu 16.04 instance using Python 3.5. The program is below;
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.PhantomJS("p/phantomjs")
driver.get("http://www.bbc.co.uk")
s = BeautifulSoup(driver.page_source, "lxml")
print(s.findAll("a"))
try:
driver.close()
except AttributeError:
pass
All the modules are installed correctly. However, when I run the program, I receive the following errors:
Traceback (most recent call last):
File "t.py", line 4, in <module>
driver = webdriver.PhantomJS("p/phantomjs")
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7fb05cd964a8>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 163, in __del__
self.stop()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
It seems as though it is an issue with Selenium rather than with PhantomJS. However, I have no idea how to make the program work properly.
In other questions similar to this, the issue seems to be with closing the headless instance. However, this error is received as soon as I try to instantiate PhantomJS.
How can this be fixed?
If p folder (as you've mentioned) located in the same directory as your script, then you might need to start your code with something like
from bs4 import BeautifulSoup
from selenium import webdriver
import os
path_to_phantom_js = os.path.dirname(__file__) + '/p/phantomjs'
driver = webdriver.PhantomJS(path_to_phantom_js)
P.S. If it not works, tell me output of print(path_to_phantom_js)
This question already has an answer here:
How to fix WebDriverException: The browser appears to have exited before we could connect? [duplicate]
(1 answer)
Closed 7 years ago.
I have a simple python script that works fine on my local machine. But if I try to run it on my vps I get an error:
Traceback (most recent call last):
File "test.py", line 15, in <module>
browser = webdriver.Firefox(profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
And here is the script:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('permissions.default.image', 2)
# Set all new windows to open in the current window instead
profile.set_preference('browser.link.open_newwindow', 1)
browser = webdriver.Firefox(profile)
browser.get('http://www.google.com/')
html = browser.page_source
print html
browser.close()
Since there is no GUI for the vps is that what is causing the error?
You have to use xvfb package to run webdriver correctly.
usr/bin/xvfb-run /usr/bin/python myfile.py
Check This link for more detail
I'm testing ebaysdk Python library that lets you connect to ebay. Now I'm trying examples from: https://github.com/timotheus/ebaysdk-python/
So far I got stuck at this example:
from ebaysdk.shopping import Connection as Shopping
shopping = Shopping(domain="svcs.sandbox.ebay.com", config_file="ebay.yaml")
response = shopping.execute('FindPopularItems',
{'QueryKeywords': 'Python'})
print response.disct()
When I run it. It gives me this error:
Traceback (most recent call last):
File "ebay-test.py", line 13, in <module>
{'QueryKeywords': 'Python'})
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 123, in execute
self.error_check()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 193, in error_check
estr = self.error()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 305, in error
error_array.extend(self._get_resp_body_errors())
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/shopping/__init__.py", line 188, in _get_resp_body_errors
dom = self.response.dom()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/response.py", line 229, in dom
return self._dom
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/response.py", line 216, in __getattr__
return getattr(self._obj, name)
AttributeError: 'Response' object has no attribute '_dom'
Am I missing something here or it could be some kind of bug in library?
Do you have a config file? I had a lot of problems getting started with this SDK. To get the yaml config file to work, I had to specify the directory that it was in. So in your example, it would be:
shopping = Shopping(domain="svcs.sandbox.ebay.com", config_file=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ebay.yaml'))
You should also be able to specify debug=true in your Shopping() declaration as in Shopping(debug=True).
Make sure if you have not, to specify your APP_ID and other necessary values in the config file.
You have the wrong domain, it should be open.api.sandbox.ebay.com. See this page on the ebaysdk github.