Selenium stopped working with Firefox, works with Safari - django

I've been using Selenium with Python 3 for a while. Yesterday it stopped working. I've tried uninstalling and reinstalling everything, but it hasn't worked. I enabled the driver for Safari, and that works, but I don't know what changed. I tried going to a different project that I haven't used in a while but functioned, thinking my code threw it off, but it doesn't work either. I know there are other posts out there similar to this, but they haven't been helpful and I wasn't sure if I should contact Mozilla/Selenium about this issue. Here are my details:
Python 3.7.1
Django 2.1
Firefox 64
Selenium 3.141.0
Geckodriver 0.23.0
I am running these in a virtual environment. Any more questions, let me know. Really confused as to what broke.
This is all of the code related to launching the browser:
class FunctionalTest(StaticLiveServerTestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def get_page(self, url_extention, window=None):
window_size = [900, 700]
if window == 'xs':
window_size = [500, 700]
elif window == 'sm':
window_size = [700, 500]
elif window == 'md':
window_size = [900, 700]
elif window == 'lg':
window_size = [1024, 768]
elif window == 'xl':
window_size = [1400, 800]
return (
self.browser.get(
self.live_server_url + url_extention
),
self.browser.set_window_size(
window_size[0],
window_size[1]
)
)
class PageFunctionTest(FunctionalTest):
def test_customer_page(self):
self.get_page('/customer/profile/1/', window='xs')
# I also tried this just to check:
self.browser.get(self.live_server_url)
Basically the browser opens, throws an error and then quits. This is what shows in the browser window:
address bar: http//localhost:59905/customer/profile/1/
browser error: Firefox can’t establish a connection to the server at localhost:59905.
And this is the traceback:
Traceback (most recent call last): File
"tests/functional_tests/test_function_profile_update_phone_number.py",
line 21, in test_update_profile_phone_number
self.get_page(f'/customer/profile/1/', window='xs') File "/base_tests/base_FunctionalTest.py", line 70, in get_page
self.live_server_url + url_extention File "/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 333, in get
self.execute(Command.GET, {'url': url}) File "/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 321, in execute
self.error_handler.check_response(response) File "/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Reached error
page:
about:neterror?e=connectionFailure&u=http%3A//localhost%3A59905/customer/profile/1/&c=UTF-8&f=regular&d=Firefox%20can%E2%80%99t%20establish%20a%20connection%20to%20the%20server%20at%20localhost%3A59905.

Related

What can cause an Assertion Error while running in Ursina?

I'm pretty new to programming with Python and am starting to learn how to use Ursina Game Engine...
Currently I'm running Python 3.9.4 through IDLE. I looked up a YouTube playlist that goes through different activities using Ursina. However I hit a snag with one of the videos. I keep receiving an Assertion Error even though I copied the code exactly as it is shown in the video.
Here is the complete Error I'm receiving:
= RESTART: C:/Users/Charbel/Desktop/Ursina Tutorials/smooth follow - flying dragon.py
package_folder: C:\Users\Charbel\AppData\Roaming\Python\Python39\site-packages\ursina
asset_folder: C:\Users\Charbel\Desktop\Ursina Tutorials
blender_paths:
{'2.7': WindowsPath('C:/Program Files/Blender Foundation/Blender/blender.exe'),
'2.8': WindowsPath('C:/Program Files/Blender Foundation/Blender 2.83/blender.exe'),
'default': WindowsPath('C:/Program Files/Blender Foundation/Blender 2.83/blender.exe')}
screen resolution: (1366, 768)
size; LVector2f(1092, 614)
render mode: default
development mode: True
application successfully started
Traceback (most recent call last):
File "C:\Users\Charbel\AppData\Roaming\Python\Python39\site-packages\direct\showbase\ShowBase.py", line 2153, in __igLoop
self.graphicsEngine.renderFrame()
AssertionError: !mat.is_nan() at line 322 of c:\buildslave\sdk-windows-amd64\build\panda\src\pgraph\transformState.cxx
Traceback (most recent call last):
File "C:/Users/Charbel/Desktop/Ursina Tutorials/smooth follow - flying dragon.py", line 22, in <module>
app.run()
File "C:\Users\Charbel\AppData\Roaming\Python\Python39\site-packages\ursina\main.py", line 238, in run
super().run()
File "C:\Users\Charbel\AppData\Roaming\Python\Python39\site-packages\direct\showbase\ShowBase.py", line 3325, in run
self.taskMgr.run()
File "C:\Users\Charbel\AppData\Roaming\Python\Python39\site-packages\direct\task\Task.py", line 546, in run
self.step()
File "C:\Users\Charbel\AppData\Roaming\Python\Python39\site-packages\direct\task\Task.py", line 500, in step
self.mgr.poll()
File "C:\Users\Charbel\AppData\Roaming\Python\Python39\site-packages\direct\showbase\ShowBase.py", line 2153, in __igLoop
self.graphicsEngine.renderFrame()
AssertionError: !mat.is_nan() at line 322 of c:\buildslave\sdk-windows-amd64\build\panda\src\pgraph\transformState.cxx
Here's a copy of my entire code:
from ursina import *
def update():
global dy
player.y += dy
if abs(player.y)>= 3:
dy = -dy
app = Ursina()
player = Entity(model='quad', scale=1, x = -4.5, texture = 'dragon_head.png')
e = [None]*50
e[0] = Entity(model='circle', scale = .2, color = color.green)
e[0].add_script(SmoothFollow(target = player, offset=(.3, 0, 0)))
dy =.08
for i in range(1,50):
e[i] = Entity(model='circle', scale = .2, color = color.green)
e[i].add_script(SmoothFollow(target = e[i-1], offset=(.2, 0, 0)))
app.run()
It appears that the error has something to do with the e[i-1] from my investigation. Has anyone else run into a similar issue or know if there's a bug in the Ursina language that causes this?
Thanks in advance
Charbel
My app just run to this error either.I think it is a rendering error caused by insufficient GPU computing power of the graphics.I reduce it to 44 and it works.
I'd assume either your computer or engine cannot handle it. I tried making a cube's rotation_z multiplied by an absurdly large number (100000000000000000000000000000000000000 to be exact) and it ran fine, but when I added an extra zero to the number, the engine broke.

WARNING: NEOS is temporarily unavailable. - Pyomo

I'm trying to learn how to send an optimization problem to NEOS Server to solve it with BARON, but I'm receiving an error which says NEOS is currently unavailable even though I've been trying it for some time. I've seen that there exists another question with the same error code, but it has not been resolved and people suspect it to be caused by using a proxy (Which I do not) therefore I opened another question.
from pyomo.environ import *
model = ConcreteModel()
model.x = Var(initialize=1.5)
model.y = Var(initialize=1.5)
def rosenbrock(model):
return (1.0-model.x)**2 + 100.0*(model.y - model.x**2)**2
model.obj = Objective(rule=rosenbrock, sense=minimize)
solver_manager = SolverManagerFactory('neos')
results = solver_manager.solve(model, opt='baron')
results.write()
And the output is:
WARNING: NEOS is temporarily unavailable.
Traceback (most recent call last):
File "/Users/dorukeski/untitled/sa.py", line 15, in <module>
results = solver_manager.solve(model, opt='baron')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/opt/parallel/async_solver.py", line 28, in solve
return self.execute(*args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/opt/parallel/manager.py", line 119, in execute
ah = self.queue(*args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/opt/parallel/manager.py", line 134, in queue
return self._perform_queue(ah, *args, **kwds)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/pyomo/neos/plugins/kestrel_plugin.py", line 128, in _perform_queue
raise ActionManagerError(
pyomo.opt.parallel.manager.ActionManagerError: Solver 'baron' is not recognized by NEOS.
Solver names recognized:
[]
Though this post is an old post.
I see someone suggested the fix in this link, https://github.com/Pyomo/pyomo/issues/2162
solution 1:
pip install --upgrade certifi
solution 2 if solution 1 not working:
1 - Open Internet Explorer as an Administrator (i.e., right-click on Internet Explorer and choose "Run as administrator")
2 - Navigate to https://neos-server.org
3 - Click on the lock icon
Click to view the image
4 - Click "View Certificate"
5 - Click "Install certificate..."
6 - Choose user or local machine, whatever is appropriate
7 - Select "Place all certificates in the following store" and choose "Trusted Root
8 - Certification Authorities"

How to take multiple screenshots through Selenium in Python?

GECKODRIVER_PATH = 'F:/geckodriver.exe'
firefox_options = Options()
firefox_options .add_argument("-headless")
driver = webdriver.Firefox(executable_path=CHROMEDRIVER_PATH, firefox_options = firefox_options )
test = []
test.append('http://google.com')
test.append('http://stackoverflow.com')
for x in test:
print x
driver.get(x)
driver.set_page_load_timeout(20)
filename = str(x)+'.png'
driver.save_screenshot( filename )
driver.close()
Now, how can I take multiple screenshots and save them in the different filename? As you can see I am trying to save the filename according to domain URL but failed.
See the error below:
http://google.com
http://card.com
Traceback (most recent call last):
File "F:\AutoRecon-master\test.py", line 125, in <module>
driver.get(x)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 326, in get
self.execute(Command.GET, {'url': url})
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Tried to run command without establishing a connection
Can anyone please tell me what is the exact problem is? Will be a big help.
Try to move driver.close() out of loop:
for x in test:
print x
driver.get(x)
driver.set_page_load_timeout(20)
filename = str(x)+'.png'
driver.save_screenshot( filename )
driver.close()
Also note that x is already a string, so there is no need in str(x)
P.S. I'm not sure that http://stackoverflow.com.png filename is acceptable, you might need to use:
filename = x.split('//')[-1] + '.png'
Tried to run command without establishing a connection
you are closing the browser within your for loop... so the 2nd time through the loop it fails with the error above (since the browser is closed, the connection to geckodriver has already been terminated).
other issues:
you are setting the page_load_timeout after you have already fetched the page, so it is not doing anything useful.
using CHROMEDRIVER_PATH as the name for Geckodriver is just confusing. Chromedriver is not used at all here.

Twitch Chat box in selenium

Well I pieced together a script with multiple google searches which is based on selenium,the intention of this code is to try to type in the chat box of twitch with a randomized message automatically(not limited use to only my channel), but it fails miserably. I have a general knowledge on python but that's it, which is why ended up here since I couldn't find the answer myself.
from selenium import webdriver
from random import randint
import keyboard
browser = webdriver.Chrome(executable_path=r'C:\Python27\Scripts\chromedriver')
browser.get('https://www.twitch.tv/alexaki99')
#getting chat box
chat=browser.find_element_by_css_selector('#root > div > div > div.tw-full-height.tw-flex.tw-flex-column.tw-flex-nowrap.tw-relative > div > div.right-column.tw-full-height.tw-flex-shrink-0.tw-relative > div > div > div.tw-full-width.tw-full-height.tw-z-default.tw-flex.tw-flex-column.tw-flex-grow-1.tw-flex-nowrap.tw-relative > div.tw-full-width.tw-full-height.tw-overflow-hidden.tw-flex.tw-flex-column.tw-flex-grow-1.tw-flex-shrink-1 > div > div.chat-input.tw-pd-b-2.tw-pd-x-2 > div.tw-z-default.tw-relative > div:nth-child(1) > textarea')
time.sleep(40) #manually logging in because of captcha
print 'done sleep' #verification that the delay
chat.click()
while True:
num=(randint(0, 7))
if num==1:
chat.send_keys('1')
if num==2:
chat.send_keys('2')
if num==3:
chat._send_keys('3')
if num==4:
chat._send_keys('4')
if num==5:
chat._send_keys('5')
if num==6:
chat._send_keys('6')
if num==7:
chat._send_keys('7')
if keyboard.is_pressed('shift+q'):
break
driver.quit()
The error I get goes as follows:
Traceback (most recent call last):
File "C:\Users\Alex\Desktop\twitch_auto.py", line 11, in <module>
chat.click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=65.0.3325.146)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.16299 x86_64)
I'm aware I could use irc twitch but I got lost quick,so I stayed with what I had.
Thanks in advance.
The "chat" you had specified is the box that you type your message("done sleep").
You have to do the same process you did finding the chat element, but now with the button element that you have on bottom right. After you found your buttom element, just need to do buttom.click().

PhantomJS webdriver error code -11 when I use uWSGI http request to launch phantomJS to grab web data

Traceback (most recent call last): File "tb_list_spider.py", line 42, in parse_tblist
driver = webdriver.PhantomJS(desired_capabilities=desired_capabilities) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
self.service.start() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code) selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: -11
Message: Service phantomjs unexpectedly exited. Status code was: -11
desired_capabilities['phantomjs.page.customHeaders.User-Agent'] = user_agent
driver = webdriver.PhantomJS(desired_capabilities=desired_capabilities) # thie line encountered exception
Above is the traceback info. When I use command line way to run my code is fine, but it is not work when I use browser http request to trigger the phantomJS by uWSGI interface.
the error code is -11,but I dont know where to find the meanning of -11. who knows the error code meaning please told me,thanks very much.
the enviroment:centos7 + python3.6.2 + phantomJS-2.1.1 + uWSGI-2.0.15 +Django-1.11.7 + selenium-3.7.0
I already know the ansows reason,this because the uWSGI's setting.
the limit-as is the cause, annotate it will recover normal.
[uwsgi]
#vhost = false
http = :80
#master = true //主进程
#vhost = true //多站模式
#no-site = true //多站模式时不设置入口模块和文件
workers = 10 //子进程数
#reload-mercy = 10
#vacuum = true //退出、重启时清理文件
#max-requests = 1000
#limit-as = 512 //这个设置uwsgi内存大小的,无法启动phantomjs就是这个导致的
buffer-size = 30000
wsgi-file = /grab_web/web_api/web_api/wsgi.py
chdir = /grab_web/web_api/web_api
enable-threads = true
#single-interpreter = true