Selenium - tuple object is not callable - python

I have a problem with test selenium - page object pattern. My code:
class FormPage(Page):
nameConnect = (By.ID, "name")
def nameUser(self,name):
names = self.driver.find_element(*FormPage.nameConnect)
names.send_keys(name)
class testUser(Page):
start_page = FormPage(self.driver)
start_page.nameUser('user22xx')
my error:
start_page.nameUser('user22xx')
TypeError: 'tuple' object is not callable
How I can change my code? Thanks for your help!

Related

AttributeError: 'str' object has no attribute 'as_plain_ordered_dict'

I am trying to mock "ConfigFactory.parse_file" for unit testing purpose and getting the following error.
AttributeError: 'str' object has no attribute 'as_plain_ordered_dict'
I tried mocking the attribute as_plain_ordered_dict to resolve the issue, but still getting the same error.
class Testt2StatsExporter(unittest.TestCase):
#patch('t2.client.OverlayClient')
#patch('pyhocon.ConfigFactory.parse_file')
#patch('oci.auth.signers.instance_principals_security_token_signer.InstancePrincipalsSecurityTokenSigner')
def test_create_telemetry_client(self, mock_config_factory, mock_security_token_signer, mock_client):
test_config = Mock()
test_config.json.return_value = {'metricsConfig': 'test_config'}
path_to_local_config = Mock()
type(path_to_local_config).as_plain_ordered_dict = PropertyMock(return_value=test_config)
mock_security_token_signer.return_value = "test_token"
mock_config_factory.return_value = test_config
mock_client.return_value = True
self.assertEqual(True, _create_telemetry_client(path_to_local_config))
and here is the main code base that I am testing.
path_to_local_config = '/etc/dlp/t2_config.conf'
def _create_telemetry_client(path_to_local_config: str):
t2config = ConfigFactory.parse_file(path_to_local_config).as_plain_ordered_dict()
common_config = t2config['metricsConfig']
t2_client_config = {'metricsConfig': common_config}
auth_provider = InstancePrincipalsSecurityTokenSigner()
return client.OverlayClient(t2_client_config, authentication_provider=auth_provider)
What can I try next?

AttributeError: 'NoneType' object has no attribute 'string' Couldn't fix this

Trying to work with BeautifulSoup but I'm getting this error:
AttributeError: 'NoneType' object has no attribute 'string'
The problem is with this line
_a = _dev.find('a')
Here is my code:
for _dev in devs:
_d = _dev.find('div')
authors.append(_d.text.strip())
_a = _dev.find('a')
if not _a.string is None:
names.append(_a.text.strip())
if 'href' in _a.attrs.keys():
urls.append(_a.get('href'))
How can I fix this?
The problem is most likely with this line if not _a.string is None:.
If _dev.find('a') does not find what you're looking for it returns None. Since you assigned the value to _a, that means you are calling None.string on that line, which will definitely raise an error.
Change that line to this:
if _a and not _a.string is None:

pyqt4: AttributeError: 'QPlainTextEdit' object has no attribute 'text'

I'm aware that there are similar problems to mine but I tried those solutions and they don't work.
I have text field:
self.tMail = QtGui.QPlainTextEdit(self.centralwidget)
self.tMail.setGeometry(QtCore.QRect(50, 270, 451, 75))
self.tMail.setAccessibleName(_fromUtf8(""))
self.tMail.setInputMethodHints(QtCore.Qt.ImhNone)
self.tMail.setPlainText(_fromUtf8(""))
self.tMail.setOverwriteMode(False)
self.tMail.setObjectName(_fromUtf8("tMail"))
And i want to add them to the variable string by:
def handleButton(self):
timeString = self.tCzas.text()
mailString = self.tMail.text()
IDString = self.tID.text()
teamString = self.tTeam.text()
print(timeString)
print(mailString)
print(IDString)
print(teamString)`
also I tried:
mailString = self.tMail.plainText()
and I always get an error:
AttributeError: 'QPlainTextEdit' object has no attribute '...'
Why?
QPlainTextEdit doesn't have a text() function. try using the toPlainText() function:
def handleButton(self):
timeString = self.tCzas.toPlainText()
mailString = self.tMail.toPlainText()
IDString = self.tID.toPlainText()
teamString = self.tTeam.toPlainText()
print(timeString)
print(mailString)
print(IDString)
print(teamString)

Regex: AttributeError: 'NoneType' object has no attribute 'group'

I'm quite new to regex.
I have an application log in a dataframe, AppEvents, which I try to split into smaller parts:
"[01/30/2018 15:01:24] [Visma.Workflow.Server.exe] Off
[CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb::0] ThreadId: 12 ThreadName:
Initializing of ERP client complete. Logged from: CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb (0)
"
Desired output:
[01/30/2018 15:01:24],
[App.Workflow.Server.exe] Off, [CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb::0],
ThreadId: 12,
ThreadName: Initializing of ERP client complete.,
Logged from: CompanyDatabaseUpgrader.CheckAndUpgradeCompanyDb (0),
What I have attempted:
regex = re.compile('(.+?)\[(.+?\])] [ThreadID$ \d+] [ThreadName$
+d+]')
res = regex.match(AppEvents.ix[2,4])
log_parts = list(res.group())
App_info = log_parts.pop(-1)
App_parts = App_info.split(' ')
log_parts.extend(App_parts)
I get AttributeError: 'NoneType' object has no attribute 'group' and I do not know why. Any help appreciated!

Modifying XML with ElementTree: 'str' object has no attribute 'text'

The following code gives the error:
line 19, in modifyXML
self.PreFlopCallPower.text = 'NEW VALUE'
AttributeError: 'str' object has no attribute 'text'
The problem seems to be that self.PreFlopCallPower is only a string and not an elementTree object, even though my example is very similar to the example given on the python etree documentation: self.PreFlopCallPower = entry.find('PreFlopCallPower').text. How can I fix this? I can't see what I'm doing different to the update example listed here: https://docs.python.org/2/library/xml.etree.elementtree.html
import xml.etree.ElementTree as xml
class XMLHandler(object):
def __init__(self,StrategyName):
self.readXML(StrategyName)
self.modifyXML()
def readXML(self, StrategyName):
self.Template = StrategyName
self.tree = xml.parse('strategies.xml')
self.root = self.tree.getroot()
for entry in self.root.findall('Strategy'):
if entry.get('name') == StrategyName:
self.PreFlopCallPower = entry.find('PreFlopCallPower').text
def modifyXML (self):
self.PreFlopCallPower.text = 'NEW VALUE' # ---ERROR OCCURS HERE---
self.PreFlopCallPower.set('updated', 'yes')
self.tree.write('output.xml')
X=XMLHandler('Strategy305PP')
In this line, you're storing the text of the node (hence have a str):
self.PreFlopCallPower = entry.find('PreFlopCallPower').text
Drop the .text to store the node itself:
self.PreFlopCallPower = entry.find('PreFlopCallPower')

Categories

Resources