I am trying to create a web driver instance in the python with the following code:
from robot.libraries.BuiltIn import BuiltIn
import Selenium2Library
from Selenium2Library import Selenium2Library
def get_webdriver_instance():
s2l = BuiltIn().get_library_instance("Selenium2Library")
return s2l._current_browser()
but at BuiltIn().get_library_instance("Selenium2Library") I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 2922, in get_library_instance
return self._namespace.get_library_instance(name)
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 70, in _namespace
return self._context.namespace
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 65, in _context
raise RobotNotRunningError('Cannot access execution context')
robot.libraries.BuiltIn.RobotNotRunningError: Cannot access execution context
Could someone please help me in resolving this error
The error message is telling you that you can't use methods of the BuiltIn library unless you are actually running a test (via pybot, jybot, etc). You can't call BuiltIn().get_library_instance('Selenium2Library') in a standalone python script.
_current_browser is only return the current browser
If you want to use Selenium2Library in python than you can do the next
from Selenium2Library import Selenium2Library
sl = Selenium2Library()
sl.open_browser('firefox')
Related
I am a junior developer and totally new to Python and Selenium. I have to learn unit testing. They shared a small repository as an example. As required I installed Python and Selenium, but I don't know how to run. I have looked some tutorials, they just installed Python and Selenium, and added chromedriver, that's it. I have completed same steps, added PYTHONPATH and everything. But still getting errors.
My PYTHONPATH variable C:\Users\yanke\altrium-systemtests\altsys
Readme.md
System tests for Altrium frontend.
Install Python
export PYTHONPATH="."
python altsys/tests.py
tests.py
""Test altrium portal"""
import unittest
from selenium import webdriver
from altsys.selenium_helpers import sreenshot_on_fail
from altsys.page import AltriumPage
#sreenshot_on_fail()
class LoginTest(unittest.TestCase):
"""Test altrium portal login
Args:
unittest ([type]): [description]
"""
def setUp(self) -> None:
self.driver = webdriver.Chrome()
# self.driver = webdriver.Firefox()
self.page = AltriumPage(self.driver, 'https://alpha.altrium.sg/login')
def test_login(self):
"""Test login
"""
self.page.login(
'tdrobiszewski+st#gmail.com',
'TestPassword123!'
)
# SLACK_TOKEN = 'xoxb-1178000328886-3062418273846-EIxTJ17QSbELkwB7WnbfHuFr'
if __name__ == '__main__':
unittest.main()
When I run I am getting these errors:
Error
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\unittest\loader.py", line 34, in testFailure
raise self._exception
ImportError: Failed to import test module: tests
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\unittest\loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "C:\Users\yanke\altrium-systemtests\altsys\tests.py", line 5, in <module>
from altsys.selenium_helpers import sreenshot_on_fail
File "C:\Users\yanke\altrium-systemtests\altsys\selenium_helpers.py", line 3, in <module>
from slack_sdk import WebClient
ModuleNotFoundError: No module named 'slack_sdk'
Ran 1 test in 0.006s
FAILED (errors=1)
Process finished with exit code 1
On Terminal
Traceback (most recent call last):
File "C:\Users\yanke\altrium-systemtests\altsys\tests.py", line 5, in <module>
from altsys.selenium_helpers import sreenshot_on_fail
ModuleNotFoundError: No module named 'altsys'
Unable to import CsvFileSource but able to install beam_utils.
I need this import to run the Cloud data flow program.
Code has -
from beam_utils.sources import CsvFileSource
Error message :
>>> from beam_utils.sources import CsvFileSource
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vk/.local/lib/python2.7/site-packages/beam_utils/sources.py", line 14, in <module>
class JsonLinesFileSource(beam.io.filebasedsource.FileBasedSource):
File "/home/vk/.local/lib/python2.7/site-packages/beam_utils/sources.py", line 17, in JsonLinesFileSource
compression_type=fileio.CompressionTypes.AUTO,
AttributeError: 'module' object has no attribute 'CompressionTypes'
>>>
I even tried import using python3.
any idea, how I can bypass.
Apache beam has recently updated and changed a few of their methods and attributes.
In particular, the fileio class is now filesystem. If you want to quickfix this, you can edit beam_utils source (python_home\lib\site-packages\beam_utils\sources.py) and replace 'fileio' for 'filesystem'. It should work ;)
If you take a look at the github repo (https://github.com/pabloem/beam_utils/blob/master/beam_utils/sources.py), the changes are already there. I guess it's a matter of time until they're added to pip!
I'm also getting the same error. I'm attemping to load csv into a dictionary and then write it to local (eventually to BQ).
argv = [
'--project={0}'.format(PROJECT),
'--staging_location=gs://{0}/'.format(BUCKET),
'--temp_location=gs://{0}/'.format(BUCKET),
#'--runner=DataflowRunner'
'--runner=DirectRunner'
]
p= beam.Pipeline(argv=argv)
rows = p | 'ReadCSV' >> beam.io.Read(CsvFileSource('gs://blahblah/file.csv')) | 'Write to file' >> beam.io.WriteToText('s
trings', file_name_suffix='.txt')```
-[snip]-
Apache Beam will soon support Python 3 only.
'You are using Apache Beam with Python 2. '
Traceback (most recent call last):
File "avg-ecom-rating.py", line 5, in <module>
from beam_utils.sources import CsvFileSource
File "/home/dlemon/env/local/lib/python2.7/site-packages/beam_utils/sources.py", line 14, in <module>
class JsonLinesFileSource(beam.io.filebasedsource.FileBasedSource):
File "/home/dlemon/env/local/lib/python2.7/site-packages/beam_utils/sources.py", line 17, in JsonLinesFileSource
compression_type=fileio.CompressionTypes.AUTO,
AttributeError: 'module' object has no attribute 'CompressionTypes'
I want to GUI automation of ADS software and for that I am using Python scripting. But I am getting error while working on menu select.
I have tried with SWAPY automation tool to get syntax but no major help from that and then I have tried with below link but still no success. pywinauto: MenuSelect() Cannot be used to select "MenuBar" in some applications. What is a suitable function from this library to use?
>>> from pywinauto.application import Application
>>> import pywinauto
>>> from pywinauto import findwindows
>>> app = pywinauto.Application().start(r"C:\Program Files\Keysight\ADS2020\bin\ads.exe")
>>> app = Application().connect(title=u'Advanced Design System 2020 (Main)', class_name='Qt5QWindowIcon')
>>> MenuItms = app.window_(title=u'Advanced Design System 2020 (Main)').MenuSelect("File->Exit")
Warning (from warnings module):
File "__main__", line 1
DeprecationWarning: Method .window_() is deprecated, use .window() instead.
Warning (from warnings module):
File "__main__", line 1
DeprecationWarning: Method .MenuSelect() is deprecated, use .menu_select() instead.
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
MenuItms = app.window_(title=u'Advanced Design System 2020 (Main)').MenuSelect("File->Exit")
File "C:\Users\aakotkar\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\__init__.py", line 50, in wrap
return method(*args, **kwargs)
File "C:\Users\aakotkar\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\controls\hwndwrapper.py", line 1083, in menu_select
self.menu_item(path, exact=exact).select()
File "C:\Users\aakotkar\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\controls\hwndwrapper.py", line 1028, in menu_item
raise RuntimeError("There is no menu.")
RuntimeError: There is no menu.
It should click on File and then select Exit
I recently tried to automate a windows application using a pywinauto since it enables automation with using python. I just started it and encountered a problem which hinders me to continue.
I get this error whenever I try to find the relevant element:
Traceback (most recent call last):
File "test.py", line 14, in <module>
app.findwindows.find_elements().click_input()
File "C:\Users\Bar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\application.py", line 173, in __call__
format(self.criteria[-1]['best_match']))
AttributeError: WindowSpecification class has no 'find_elements' method
This is my code:
from pywinauto.application import Application
import pywinauto
import time
app = Application(backend='uia').start(r"C:\Program
Files\Intellech\Analyzer\Suite.exe")
time.sleep(3)
app.findwindows.find_windows(auto_id='btQuick').click_input()
Can you help me to find out the reason of this error?
findwindows is a module name, not an attribute of Application object. This is correct code for the last line:
app.window(title="Your Main Window").child_window(auto_id='btQuick').click_input()
where "Your Main Window" should be changed to correct text of the top level window.
I'm trying to create a new FileCookieJar using cookielib in Python 2.6. However, when I do so I get the following error:
Traceback (most recent call last):
File "C:\Users\Paul\getfile.py", line 7, in <module>
cj.load(os.getcwd()+'\cookies.txt')
File "C:\Python26\lib\cookielib.py", line 1763, in load
self._really_load(f, filename, ignore_discard, ignore_expires)
AttributeError: FileCookieJar instance has no attribute '_really_load'
My code is as follows:
import cookielib, urllib2, os
cj = cookielib.FileCookieJar()
cj.load(os.getcwd()+'\cookies.txt')
I've not used Python in years but need to for a small project. Can anyone help?
FileCookieJar is a kind of abstract class (i.e. it has some functionality unimplemented). You probably want to use one of its children - MozillaCookieJar, MSIECookieJar or LWPCookieJar.