[英]Verify input box text using Python + Selenium
I have gone through other similar questions and the general advice was to use the get_attribute()
method with input 'value'
. 我经历了其他类似的问题,一般建议是将
get_attribute()
方法与输入'value'
。
However, this doesn't seem to work in my case. 但是,这似乎不适用于我的情况。
The tag I am trying to test is -: 我要测试的标签是-:
<input class="form-control required" id="email" name="email" placeholder="Enter your E-mail / Username" required="" type="text" value="">
and the code I am using is as follows -: 我正在使用的代码如下-:
def enter_keys_by_id(self, id, text):
"""
Finds a form element by ID and then proceeds
to enter text into the form.
"""
find_element = self.driver.find_element_by_id(id)
assert find_element.get_attribute('value') == ""
find_element.send_keys(text)
assert find_element.get_attribute('value') == text
return find_element
with the function call -: 与函数调用-:
enter_keys_by_id("email", "someemail@email.com")
The 'value'
attribute is set to blank in the tag. 标签中的
'value'
属性设置为空白。 How would I go about it in this particular case? 在这种情况下,我将如何处理?
So, you type email to the "empty" input, but I think that you need to submit the form, ie save
the value
to the input before retrieveing it. 所以,你键入电子邮件到“空”的输入,但我认为你需要提交的形式,即
save
了value
retrieveing之前将其输入。 I guess you are trying to verify that the email was saved correctly, so you can: 我猜您正在尝试验证电子邮件是否正确保存,因此您可以:
assert find_element.get_attribute('value') == text
(or to wait for the input with value='your text') assert find_element.get_attribute('value') == text
(或者等待value ='your text'的输入)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.