Python Selenium - AttributeError : WebElement object has no attribute sendKeys in textarea

試著忘記壹切 提交于 2021-02-02 09:39:25

问题


My code :

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
driver=webdriver.Firefox()
driver.get("http://www.58yumi.com/")
driver.find_element_by_id("UserName").send_keys("XXXXXXX")
driver.find_element_by_id("Password").send_keys( "XXXXXX")
driver.find_element_by_xpath("//*[contains(@type,'submit')]").click()
driver.get("http://www.58yumi.com/user_jiexi.htm")
driver.find_element_by_id("cznr").sendKeys("XXXX.com|forcname|CNAME|forcname.XXXX.com.a.bdydns.com|default");
......

I get error in element_by_id("cznr") :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'WebElement' object has no attribute 'sendKeys'

html :

<textarea id="cznr" onkeyup="czhang();" name="ymlb" cols="60" class="inputs2" rows="10"></textarea>

Help .... How to input data in textarea ?


回答1:


Replace sendKeys() which is Java based method with Python based method send_keys() in the line:

driver.find_element_by_id("cznr").sendKeys("XXXX.com|forcname|CNAME|forcname.XXXX.com.a.bdydns.com|default");



回答2:


You're using the wrong function name -- sendKeys vs. send_keys.

You must have copied that line from a Java sample program, which does use sendKeys as the function name.



来源:https://stackoverflow.com/questions/53953043/python-selenium-attributeerror-webelement-object-has-no-attribute-sendkeys-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!