gpt4 book ai didi

selenium - Pytest Selenium elem.send_keys() 导致 TypeError : object of type 'NoneType' has no len()

转载 作者:行者123 更新时间:2023-12-04 16:45:51 27 4
gpt4 key购买 nike

我正在尝试将数据发送到登录文本框,但是当我使用“send_keys”时出现错误..

def wait_for_element(selenium, selenium_locator, search_pattern, wait_seconds=10):
elem = None
wait = WebDriverWait(selenium, wait_seconds)

try:
if (selenium_locator.upper() == 'ID'):
elem = wait.until(
EC.visibility_of_element_located((By.ID, search_pattern))
)
except TimeoutException:
pass

return elem

userid=os.environ.get('userid')
wait_for_element(selenium, "ID", 'username')
assert elem is not None
elem.click()
time.sleep(3)
elem.send_keys(userid)

tests\util.py:123: in HTML5_login elem.send_keys(userid) ..\selenium\webdriver\remote\webelement.py:478: in send_keys {'text': "".join(keys_to_typing(value)),


value = (None,)

def keys_to_typing(value):
"""Processes the values that will be typed in the element."""
typing = []
for val in value:
if isinstance(val, Keys):
typing.append(val)
elif isinstance(val, int):
val = str(val)
for i in range(len(val)):
typing.append(val[i])
else:
for i in range(len(val)):
         for i in range(len(val)):

E TypeError: object of type 'NoneType' has no len()



我不知道为什么当我让它通过断言以及单击元素时它说元素是“NoneType”。当我运行测试时,我什至可以看到它点击了元素!

最佳答案

这个错误信息...

elem.send_keys(userid) ..\selenium\webdriver\remote\webelement.py:478: in send_keys {'text': "".join(keys_to_typing(value)), value = (None,)
TypeError: object of type 'NoneType' has no len()

...意味着 send_keys()方法在发送变量 的内容时遇到错误用户 ID .

尽管您尝试使用变量 用户 ID ,我没有看到变量 用户 ID 在代码块中的任何位置声明。因此,您会看到错误:

TypeError: object of type 'NoneType' has no len()



解决方案

初始化 用户 ID 变量为:
userid = "Austin"

现在,执行您的测试。

关于selenium - Pytest Selenium elem.send_keys() 导致 TypeError : object of type 'NoneType' has no len(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59203588/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com