selenium 的find_element返回值是一个字典

用selenium+python去测试electron应用程序,代码入下:

options = webdriver.ChromeOptions()
options.binary_location = '\\start.exe'
driver_path = 'chromedriver.exe'
service = webdriver.chrome.service.Service(driver_path)

service.start()
sleep(5)

driver = webdriver.Chrome(service=service, options=options, desired_capabilities=cap)

username = driver.find_element(By.ID, 'username')
print(username)
driver.quit()

print返回值是这样的:
{'ELEMENT': '0.32250651861538504-1'}

我觉得应该返回一个webelement元素啊,为什么返回的是一个字典?

driver.find_element_by_id('id_str')这样取写试一试。

因为返回值是字典,所以不能使用click()或者sendkeys等方法:


driver.find_element(By.ID, 'username').click()

报错:

    driver.find_element(By.ID, 'username').click()
AttributeError: 'dict' object has no attribute 'click'

问题已解决。
感谢stackoverflow。。