I am trying to access the from property of an item while accessing JIRA. Python gives me a syntax error. What could be the problem?
for history in changelog.histories:
for item in history.items:
if (item.field.upper() == 'SPRINT'):
try:
if item.fromString:
sFromSprint = str(100) #python does not like item.from
else:
sFromSprint = str(iZERO)
Error:
iFromSprint = item.from
^
SyntaxError: invalid syntax
from is a reserved keyword in python
You can get the property using getattr(item,'from') instead.
Related
Element:
XPATH:
//*[#id="autocomplete_code"]
I am getting syntax error for below statement, what is not correct in this xpath? I tried just with id and both id & class.
account = driver.find_element(By.XPATH,"//*input[#id='autocomplete_code' and #class = 'account_code_ac inputSearch ui-autocomplete-input']")
changing code as below fixed the syntax error, but still not able to select the search result value with arrow down key
account = driver.find_element(By.XPATH,"//*[#id='autocomplete_code']")
account.send_keys("1100-1200-200167-620038")
account.send_keys(Keys.ARROW_DOWN)
account.send_keys(Keys.RETURN)
changing code as below works fine:
account =driver.find_element(By.XPATH,"//*[#aria-label='Search an Account']").click()
account = driver.find_element(By.XPATH,"//*[#id='autocomplete_code']")
account.send_keys("1100-1200-200167-620038")
element = wait.until(EC.visibility_of_element_located((By.XPATH, '//a[contains(#aria-label, "1100-1200-200167-620038")]')))
account.send_keys(Keys.ARROW_DOWN)
account.send_keys(Keys.RETURN)
Im writing a google forms submitter and I'm having problems with the textfield-type questions.
Basically I am using:
textfield = question.find_element_by_class_name("quantumWizTextinputPaperinputInput")
to find the textfield and then the problems start coming in. The type of "textfield" is:<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="1b49148e-2a24-4efb-b3a5-e84be92223ae", element="3b437c8b-8d05-4410-8047-bcac9ea81f0f")>
and when I want to call .send_keys(string) on it it says that Exception has occurred: AttributeError 'list' object has no attribute 'send_keys'
So basically it says that the element returned is a list (noenetheless that type() returns a firefoxwebdriver element type).
So if I try to go with textfield[0] or textfield[1] etc... it of course throws an error that a FirefoxWebDriver is not subscribable.
What the frick?
Here's the block of code:
buttons = question.find_elements_by_class_name("appsMaterialWizToggleRadiogroupRadioButtonContainer")
buttons2 = question.find_elements_by_class_name("quantumWizTogglePapercheckboxInnerBox")
try:
textfield = question.find_element_by_class_name("quantumWizTextinputPaperinputInput")
except:
print("not found")
textfield = []
pass
And then below to send keys into it:
if len(buttons) == 0 and len(buttons2) == 0:
print(textfield)
textfield.send_keys("lol spam")
try:
textfield = question.find_element_by_class_name("quantumWizTextinputPaperinputInput")
except:
print("not found")
textfield = []
pass
The problem lies within this snippet. If textfield, or to be more specific the class_name quantumWizTextinputPaperinputInput can't be found, Python continues to evaluate the except block. Within there you stated textfield = [] - that's the reason for your problems:
Exception has occurred: AttributeError 'list' object has no attribute
'send_keys' So basically it says that the element returned is a list
(noenetheless that type() returns a firefoxwebdriver element type). So
if I try to go with textfield[0] or textfield[1] etc... it of course
throws an error that a FirefoxWebDriver is not subscribable.
You can't send send_keys to a list.
List is empty, hence a textfield[0] should throw IndexError.
A solution to this problem is to find the proper class_name. Without a HTML code we can't help you to do that.
I'm trying to describe one of the Elastic IPs in my environment but getting below error:
>>> ec2 = boto3.client('ec2', 'ap-south-1')
>>> response = client.describe_addresses(
... Filters=[
... AllocationIds=['eipalloc-000f89e6a8a331b84','eipalloc-03d4d2f93bdcb134d']
File "<stdin>", line 3
AllocationIds=['eipalloc-000f89e6a8a331b84','eipalloc-03d4d2f93bdcb134d']
^
SyntaxError: invalid syntax
The link I'm referring is https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_addresses
Please can anyone suggest what I'm doing wrong.
From the documentation Filters and AllocationIds are separate parameters to describe_addresses().
Perhaps what you are looking for is: (with suitable extra fields)
response = client.describe_addresses(Filters=[], AllocationIds=['eipalloc-000f89e6a8a331b84','eipalloc-03d4d2f93bdcb134d'])
I have a Select tag with several options (pictured below). I want to write a selenium test where I verify that the option with the 18 value is selected.
I have tried this but it doesn't work:
`age_min = self.browser.find_element_by_css_selector('select#age-min > option[value="18"]')
age_min_selected = is_attribtue_present(age_min, 'selected')
self.assertTrue(age_min_selected)`
I get this error: NameError: name 'is_attribtue_present' is not defined
I've also tried this:
`age_min = self.browser.find_element_by_css_selector('select#age-min > option[value="18"]["selected"]')`
error: Message: invalid selector: An invalid or illegal selector was specified
You could check the "selected" attribute on the option as such:
options = driver.find_elements_by_xpath("//option")
for option in options:
is_selected = option.is_selected()
print(str(is_selected))
Based on this documentation:
https://selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html?highlight=is_selected#selenium.webdriver.remote.webelement.WebElement.is_selected
Learning python (was chosen for its ldap module) for a new script that has been tossed my way. I'm getting a sytntax error when I try using a ldif. I was getting Syntax errors on the attrs I was trying to assign until I moved it further up the script to near the search fields. I'm not exactly sure why I am getting the syntax error:
File "UserGroupModify.py", line 66
attrs = {}
^
SyntaxError: invalid syntax
~/Scripts/Termination-Script$ python2 UserGroupModify.py
File "UserGroupModify.py", line 69
ldif = modlist.addModlist(attrs)
^
SyntaxError: invalid syntax
The code currently looks like the following (including previous things I had tried all with syntax errors of their own when I tried to use them). Getting it to log in and search for the user was easy enough, but modifying the user is where I am having a hard time. The current code is uncommented and is from an example I found online.
#!/usr/bin/env python2
import ldap
import getpass
import ldap.modlist as modlist
## first you must open a connection to the server
try:
#Ignore self signed certs
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
username = raw_input("LDAP Login: ")
passwd = getpass.getpass()
userlook = raw_input("User to lookup: ")
l = ldap.initialize("ldaps://ldap.example.com:636/")
# Bind/authenticate with a user with apropriate rights to add objects
l.simple_bind_s("uid="+username+",ou=people,dc=example,dc=com", ""+passwd+"")
except ldap.LDAPError, e:
print(e)
# The dn of our existing entry/object
dn = "ou=People,dc=example,dc=com"
searchScope = ldap.SCOPE_SUBTREE
searchAttribute = ["uid"]
#retrieveAttributes = ["ou=Group"]
retrieveAttributes = ["ou"]
#searchFilter = "uid=*"
searchFilter = "(uid="+userlook+")"
#mod_attrs = [(ldap.MOD_REPLACE, 'ou', 'former-people' )]
attrs = {}
attrs['member'] = ['uid="+userlook+",ou=former-people,dc=example,dc=com']
try:
#ldap_result_id = l.search(dn, searchScope, searchFilter, retrieveAttributes)
ldap_result_id = l.search(dn, searchScope, searchFilter, retrieveAttributes)
while 1:
result_type, result_data = l.result(ldap_result_id, 0)
if (result_data == []):
break
else:
## here you don't have to append to a list
## you could do whatever you want with the individual entry
## The appending to list is just for illustration.
if result_type == ldap.RES_SEARCH_ENTRY:
print(result_data)
# Some place-holders for old and new values
#old={'Group':'l.result(ldap_result_id, 0)'}
#new={'Group':'uid="+userlook+",ou=former-people,dc=example,dc=com'}
#newsetting = {'description':'I could easily forgive his pride, if he had not mortified mine.'}
#print(old)
#print(new)
# Convert place-holders for modify-operation using modlist-module
#ldif = modlist.modifyModlist(old,new)
# Do the actual modification
#l.modify_s(dn,ldif)
#l.modify_s('uid="+userlook+,ou=People,dc=example,dc=com', mod_attrs)
#l.modify_s('uid="+userlook+",ou=People', mod_attrs)
#moved up due to SyntaxError
#attrs = {}
#attrs['member'] = ['uid="+userlook+",ou=former-people,dc=example,dc=com']
# Convert our dict to nice syntax for the add-function using modlist-module
ldif = modlist.addModlist(attrs)
# Do the actual synchronous add-operation to the ldapserver
l.add_s(dn,ldif)
# Its nice to the server to disconnect and free resources when done
l.unbind_s()
except ldap.LDAPError, e:
print(e)
Any direction pointing on what's causing the error would be greatly appreciated. Thanks
It's a syntax error to have try without except. Because there's a whole lot of unindented code before the except, Python doesn't see it as part of the try. Make sure everything between try and except is indented.
You haven't ended your try block by the time you reach this line
ldif = modlist.addModlist(attrs)
since the accompanying except is below. However, you reduced the indentation level and this is causing the syntax error since things in the same block should have the same indentation.