问题
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