I started using SST (selenium simple test) but ran into a problem when executing what seems to be a valid xpath expression '//div[div#data-type="folder-name"]'. SST fails with the following traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/sst/cases.py", line 207, in run_test_script exec self.code in self.context
File "./sst-one.py", line 7, in <module> names = get_elements_by_xpath('//div[div#data-type="folder-name"]')
File "/usr/local/lib/python2.7/dist-packages/sst/actions.py", line 1344, in >get_elements_by_xpath_raise(msg)
File "/usr/local/lib/python2.7/dist-packages/sst/actions.py", line 118, in _raise raise AssertionError(msg)
AssertionError: Element not found: Message: u'The given selector //div[div#data->type="folder-name"] is either invalid or does not result in a WebElement. The following >error occurred:\nInvalidSelectorError: Unable to locate an element with the xpath >expression //div[div#data-type="folder-name"] because of the following >error:\n[Exception... "The expression is not a legal expression." code: "12" nsresult: >"0x805b0033 (SyntaxError)" location: "file:///tmp/tmp12zCta/extensions/fxdriver#googlecode.com/components/driver_component.js> Line: 5916"]' ;
Stacktrace:
at FirefoxDriver.annotateInvalidSelectorError_ (file:///tmp/tmp12zCta/extensions/fxdriver#googlecode.com/components/driver_component.js:8873)
at FirefoxDriver.prototype.findElementsInternal_ (file:///tmp/tmp12zCta/extensions/fxdriver#googlecode.com/components/driver_component.js:8931)
at FirefoxDriver.prototype.findElements file:///tmp/tmp12zCta/extensions/fxdriver#googlecode.com/components/driver_component.js:8935)
at DelayedCommand.prototype.executeInternal_/h file:///tmp/tmp12zCta/extensions/fxdriver#googlecode.com/components/command_processor.js:10840)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp12zCta/extensions/fxdriver#googlecode.com/components/command_processor.js:10845)
at DelayedCommand.prototype.execute/< file:///tmp/tmp12zCta/extensions/fxdriver#googlecode.com/components/command_processor.js:10787)
The SST code line is:
names = get_elements_by_xpath('//div[div#data-type="folder-name"]')
If I run the same xpath statement using selenium (from python), not SST, it is a valid expression and returns the matching elements if there were any.
The pure selenium code line (where br is the firefox webdriver object) is:
elems = br.find_elements_by_xpath("//div[div/#data-type='folder-name']")
I understand this is a bit in the weeds, so if anyone has some hints as to how to debug the .js code that selenium creates in the /tmp directory that would be a big help.
It's not a valid XPath expression. This
//div[div#data-type="folder-name"]
Should probably read
//div[div/#data-type="folder-name"]
which is indeed what you have in one of your examples.
If you are trying to get all possible div tags with data-type="folder-name",
//div[#data-type="folder-name"]
If only children of the first div with data-type="folder-name",
//div[div/#data-type="folder-name"]
You don't show any markup, up i assuming you have
<div><div data-type="folder-name"></div></div>
you need:
elems = br.find_elements_by_xpath("//div//div[#data-type='folder-name']")
Related
I've been having a problem lately where I can't access the value of any variable through their name. It's not a connection problem since I can read the value from the read() function just fine. However whenever I use the read_by_name function there's always the same error pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).
Because it's an unknown error I haven't been able to find documentation on it. I'm using a BC9120 as a PLC and TwinCat 2. Does anyone know what might be causing this?
Code:
if self.plc.is_open == False:
self.plc.open()
print(self.plc.read(pyads.INDEXGROUP_MEMORYBIT, 0*8 + 0, pyads.PLCTYPE_BOOL))
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
Logs:
False
Traceback (most recent call last):
File "c:\Users\MAP9AV\Documents\Banca\Modelo Preditivo\Thread_Sup.py", line 50, in run
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\connection.py", line 540, in read_by_name
return adsSyncReadByNameEx(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 1154, in adsSyncReadByNameEx
handle = adsGetHandle(port, address, data_name)
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 890, in adsGetHandle
handle = adsSyncReadWriteReqEx2(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 774, in adsSyncReadWriteReqEx2
raise ADSError(err_code)
pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).
I am getting this error in pip search while studying python.
The picture is an error when I pip search. Can you tell me how to fix it?
$ pip search pdbx
ERROR: Exception:
Traceback (most recent call last):
File "*/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 224, in _main
status = self.run(options, args)
File "*/lib/python3.7/site-packages/pip/_internal/commands/search.py", line 62, in run
pypi_hits = self.search(query, options)
File "*/lib/python3.7/site-packages/pip/_internal/commands/search.py", line 82, in search
hits = pypi.search({'name': query, 'summary': query}, 'or')
File "/usr/lib/python3.7/xmlrpc/client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python3.7/xmlrpc/client.py", line 1452, in __request
verbose=self.__verbose
File "*/lib/python3.7/site-packages/pip/_internal/network/xmlrpc.py", line 46, in request
return self.parse_response(response.raw)
File "/usr/lib/python3.7/xmlrpc/client.py", line 1342, in parse_response
return u.close()
File "/usr/lib/python3.7/xmlrpc/client.py", line 656, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault -32500: 'RuntimeError: This API has been temporarily disabled due to unmanageable load and will be deprecated in the near future. Please use the Simple or JSON API instead.'>
The pip search command queries PyPI's servers, and PyPI's maintainers have explained that the API endpoint that the pip search command queries is very resource intensive and too expensive for them to always keep open to the public. Consequently they sometimes throttle access and are actually planning to remove it completely soon.
See this GitHub issues thread ...
The solution I am using for now is to pip install pip-search (a utility created by GitHub user #victorgarric).
So, instead of 'pip search', I use pip_search. Definitely beats searching PyPI via a web browser
Follow the suggestion from JRK at the discussion at github (last comment) the search command is temporarily disabled, use your browser to search for packages meanwhile:
Check the thread on github and give him a thumb up ;)
search on website, https://pypi.org/,
then install the package you wanted
The error says
Please use the Simple or JSON API instead
You can try pypi-simple to query the pip repository
https://pypi.org/project/pypi-simple/
It gives an example too, I tried to use it here:
pypi-simple version 0.8.0 DistributionPackage' object has no attribute 'get_digest':
!/usr/bin/env python3
-*- coding: utf-8 -*-
"""
Created on Thu Nov 11 17:40:03 2020
#author: Pietro
"""
from pypi_simple import PyPISimple
def simple():
package=input('\npackage to be checked ')
try:
with PyPISimple() as client:
requests_page = client.get_project_page(package)
except:
print("\n SOMETHING WENT WRONG !!!!! \n\n",
"CHECK INTERNET CONNECTION OR DON'T KNOW WHAT HAPPENED !!!\n")
pkg = requests_page.packages[0]
print(pkg)
print(type(pkg))
print('\n',pkg,'\n')
print('\n'+pkg.filename+'\n')
print('\n'+pkg.url+'\n')
print('\n'+pkg.project+'\n')
print('\n'+pkg.version+'\n')
print('\n'+pkg.package_type+'\n')
#print('\n'+pkg.get_digest()+'\n','ENDs HERE !!!!') #wasnt working
if __name__ == '__main__':
simple()
got -4 so far for this answer don't know why , figureout I can try to check for a package with:
# package_name = input('insert package name : ')
package_name = 'numpy'
import requests
url = ('https://pypi.org/pypi/'+package_name+'/json')
r = requests.get(url)
try:
data = r.json()
for i in data:
if i == 'info':
print('ok')
for j in data[i]:
if j == 'name':
print((data[i])[j])
print([k for k in (data['releases'])])
except:
print('something went south !!!!!!!!!!')
Please find the GitLab repo for the terraform scripts which we are using.
enter link description here
Run in terraform plan gives the below error in an all-in-one.YAML file for the elastic search.
Error: Error in function call
on kubernetes.tf line 49, in locals:
49: resource_list = yamldecode(file("${path. module}/all-in-one.yaml")).items
|----------------
| path.module is "."
Call to function `"yamldecode"` failed: on line 458, column 1: unexpected extra
content after value.
enter image description here
As is describe in the fine manual:
Only one YAML document is permitted. If multiple documents are present in the given string then this function will return an error.
and one can trivially reproduce your error message:
content = yamldecode("---\nhello: world\n---\ntoo: bad\n")
on main.tf line 14, in resource "local_file" "example":
14: content = yamldecode("---\nhello: world\n---\ntoo: bad\n")
Call to function "yamldecode" failed: on line 2, column 1: unexpected extra
content after value.
I created fake header files under pycparser/utils/fake_libc_include for every header found in kernel/sched/core.c and put
#include "_fake_defines.h"
#include "_fake_typedefs.h"
into them. A few other header files where missing, lot's of headers from kernel/sched/sched.h for example. So I added them too.
Preprocessed the whole stuff with
gcc -nostdinc -E -Ipycparser/utils/fake_libc_include ../kernel/sched/core.c > core_pp.c
which gave no error.
So I tried to get the function names
python3 examples/func_defs.py core_pp.c
but it gives me the error:
Traceback (most recent call last):
File "examples/func_defs.py", line 46, in <module>
show_func_defs(filename)
File "examples/func_defs.py", line 34, in show_func_defs
cpp_args=r'-Iutils/fake_libc_include')
File "/usr/local/lib/python3.4/dist-packages/pycparser/__init__.py", line 93, in parse_file
return parser.parse(text, filename)
File "/usr/local/lib/python3.4/dist-packages/pycparser/c_parser.py", line 151, in parse
debug=debuglevel)
File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 1181, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 193, in call_errorfunc
r = errorfunc(token)
File "/usr/local/lib/python3.4/dist-packages/pycparser/c_parser.py", line 1721, in p_error
column=self.clex.find_tok_column(p)))
File "/usr/local/lib/python3.4/dist-packages/pycparser/plyparser.py", line 55, in _parse_error
raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: ../kernel/sched/cpupri.h:14:2: before: atomic_t
What am I doing wrong? I've tried the redis example from this blog entry and it worked.
Adding the headers is just one part of the solution - this helps the preprocessor resolve the #include statements.
The other part of the solution is adding types that the parser would expect to find there to _fake_typedefs. This way pycparser will know the identified is a type and will be able to parse the code properly.
I'm trying to use a parameter expression in the plone.app.theming theming-controlpanel that gets a value from the portal_registry to use within the rules.xml file of the theme.
The goal is that if a boolean is set in the registry, the theme can allow/disallow certain content.
So my parameter expression (in theming-controlpanel) is
enable_ad_tags = python:context.portal_registry['lw.portal.enableadtags']
There is a corresponding boolean field in the portal_registry.
The rules.xml file has this rule:
<!-- Global Ad Tags -->
<drop css:theme="#globalAdTags" if="not($enable_ad_tags)" />
The problem is that on my local machine i get this error in the console all the time:
c2014-08-08 09:49:19 ERROR plone.transformchain Unexpected error whilst trying to apply transform chain
Traceback (most recent call last):
File "/Users/aaronwilliams/.buildout/eggs/plone.transformchain-1.0.3-py2.7.egg/plone/transformchain/transformer.py", line 48, in __call__
newResult = handler.transformIterable(result, encoding)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/transform.py", line 179, in transformIterable
params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/utils.py", line 630, in prepareThemeParameters
params[name] = quote_param(expression(expressionContext))
File "/Users/aaronwilliams/.buildout/eggs/Zope2-2.13.20-py2.7.egg/Products/PageTemplates/ZRPythonExpr.py", line 48, in __call__
return eval(self._code, vars, {})
File "PythonExpr", line 1, in <expression>
File "/Users/aaronwilliams/.buildout/eggs/AccessControl-3.0.6-py2.7-macosx-10.8-x86_64.egg/AccessControl/ImplPython.py", line 675, in guarded_getattr
v = getattr(inst, name)
AttributeError: 'DirectoryResource' object has no attribute 'portal_registry'
Is there a problem with the pattern I am trying to use here?
Is there a better/safer way to achieve this?
Using portal instead of context works:
enable_ad_tags = python:portal.portal_registry['lw.portal.enableadtags']
IMHO context should also work, or context does not behave like it does, or the naming is wrong.