Python Selenium TypeError:无法连接“ str”和“ WebElement”对象

里亚兹·拉达尼(Riaz Ladhani)

我正在将Python与Selenium Webdriver一起使用,我有一个文本字段的值是1,000.000。我正在使用if语句来检查文本字段的值是否= 1,000.000。如果是,那么请通过其他方式,我使用send_keys并在文本字段中输入1,000.000。

我收到以下错误:TypeError:无法连接“ str”和“ WebElement”对象

Error
Traceback (most recent call last):
File "C:\Webdriver\reverted to backup\ClearCore 501\TestCases\DataPreviewsPage_TestCase.py", line 93, in test_add_DataPreviews
dp.is_maxrecords_1000_displayed()
File "C:\Webdriver\reverted to backup\ClearCore 501\Pages\data_previews.py", line 76, in is_maxrecords_1000_displayed
print "max_records_textfield does not have default value 1,000.00 The value  is = " + max_records_textfield
TypeError: cannot concatenate 'str' and 'WebElement' objects

我的代码段是:

最大记录文本字段的默认值为1,000.000

    def is_maxrecords_1000_displayed(self):
        max_records_textfield = self.driver.find_element(*MainPageLocators.datapreviews_maxrecords_textfield2)
        print "max_records_textfield = ",  max_records_textfield.get_attribute('value')
        if max_records_textfield.get_attribute('value') == "1,000.000":
            print "max_records_textfield" + max_records_textfield.get_attribute('value')
        else:
            print "max_records_textfield does not have default value 1,000.00 The value is = " + max_records_textfield
            print "Going to enter 1,000.00 into the textfield"
            max_records_textfield.send_keys("1,000.00")

我是否需要将webelement(max_records_textfield)强制转换为字符串变量?我该怎么办?

阿南德·库玛(Anand S Kumar)

错误消息非常清楚,您正在尝试将字符串与WebElement对象连接在一起

如果要打印其值,请使用- max_records_textfield.get_attribute('value')(就像在if条件和if内的print语句中使用的那样)-

print "max_records_textfield does not have default value 1,000.00 The value is = " + max_records_textfield.get_attribute('value')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Selenium / Python TypeError:“ WebElement”对象不可迭代

Python:TypeError无法连接'str和'list'对象

Python:TypeError:无法连接“ str”和“ int”对象

TypeError:无法连接'str'和'function'对象的python文件

Python TypeError:无法连接“ str”和“ list”对象

TypeError:“ WebElement”对象不是使用Selenium和Python提交表单的下标错误

TypeError:无法连接“ str”和“ UUID”对象

TypeError:无法连接“ str”和“ Redditor”对象

Python:TypeError:无法连接“str”和“int”

TypeError:无法通过Python使用Selenium调用'str'对象

Python TypeError:尝试打印时无法连接“ str”和“ int”对象

TypeError:无法连接'str'和'NoneType'对象python bs4

rpsls游戏“(python)错误:无法连接'str'和'int'对象

TypeError:无法连接“ str”和“ float”对象:pandas

TypeError:无法连接“ str”和“ pygame.Surface”对象

re.search()TypeError:无法连接“ str”和“ NoneType”对象

Tkinter Label,TypeError:无法连接“ str”和“ instance”对象

abaqus脚本:TypeError:无法连接“ str”和“ Set”对象

TypeError:“str”对象在 selenium python 中不可调用

Python以及如何从Selenium元素WebElement对象获取文本?

“WebElement”类型的对象没有 len() - Python Selenium

无法从 Webelement Selenium Python 打印文本

openerp无法连接“ str”和“ function”对象

无法在 Python 中连接 str 和 int

Python错误:无法连接“ str”和“ builtin_function_or_method”对象

Python TypeError:无法在邮件的电子邮件正文部分中串联“ str”和“ list”对象

TypeError:无法连接电子邮件中的“ str”和“ list”对象

TypeError:无法连接类型为“ <class'str'>”的对象;仅Series和DataFrame objs有效

TypeError:无法使用MySQL连接Flask中的'str'和'float'对象