我尝试使用Selenium编写Web自动化代码,但总是收到错误消息:
textArea.send_Keys(用户名)AttributeError:'WebElement'对象具有 没有属性“ send_Keys”
有人可以帮助我吗? 而且我知道我还没有完成代码,可以缩短文本的长度,但是我只希望它现在可以工作。
代码如下:
def commentAndLike():
random.seed()
likeOrNext = random.randint(0, 3)
if likeOrNext == 0:
if check_exists_by_xpath("/html/body/div[3]/div[2]/div/article/div[2]/section[1]/span[1]/button/span"):
likeButton = browser.find_element_by_xpath("/html/body/div[3]/div[2]/div/article/div[2]/section[1]/span[1]/button/span")
likeButton.click()
time.sleep(randomNumber(6, 10))
if check_exists_by_xpath("/html/body/div[3]/div[2]/div/article/div[2]/section[1]/span[2]/button/span"):
random.seed()
randomComment = random.randint(0, 3)
commenButton = browser.find_element_by_xpath("/html/body/div[3]/div[2]/div/article/div[2]/section[1]/span[2]/button/span")
commenButton.click()
time.sleep(randomNumber(2, 4))
textArea = browser.find_element_by_xpath("/html/body/div[3]/div[2]/div/article/div[2]/section[3]/div[1]/form/textarea")
time.sleep(randomNumber(2, 4))
if randomComment == 0:
textArea.send_keys(username)
elif randomComment == 1:
textArea.send_Keys(username)
elif randomComment == 2:
textArea.send_Keys(username)
elif randomComment == 3:
textArea.send_Keys(username)
time.sleep(randomNumber(15, 30))
postButton = browser.find_element_by_xpath("/html/body/div[3]/div[2]/div/article/div[2]/section[3]/div/form/button")
postButton.click()
time.sleep(randomNumber(20, 25))
nextButton2 = browser.find_element_by_xpath("/html/body/div[3]/div[1]/div/div/a[2]")
nextButton2.click()
time.sleep(randomNumber(15, 20))
else:
nextButton4 = browser.find_element_by_xpath("/html/body/div[3]/div[1]/div/div/a[2]")
nextButton4.click()
time.sleep(randomNumber(20, 25))
else:
nextButton1 = browser.find_element_by_xpath("/html/body/div[3]/div[1]/div/div/a[2]")
nextButton1.click()
time.sleep(randomNumber(20, 25))
else:
nextButton = browser.find_element_by_xpath("/html/body/div[3]/div[1]/div/div/a[2]")
nextButton.click()
time.sleep(randomNumber(20,25))
答案 0 :(得分:1)
const filter = [
{
"$match": {
"$and": [
// Other filters
{ "_id": { "$mod": [<number of instances>, <this instance's id>]}}
]
}
}
];
的语法错误,K应该为小写:send_Keys
。
一些文档可以帮助您使用其他语法:https://selenium-python.readthedocs.io/getting-started.html