[英]Why send_keys function doesn't work in Python Selenium?
我的代码有问题。
for photolink in all_links:
self.browser.get(photolink) #Link öffnen
time.sleep(random.randint(5, 6))
#liken
self.browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[1]/article/div/div[2]/div/div[2]/section[1]/span[1]/button').click()
time.sleep(random.randint(1, 3))
#kommentieren
commentbox = self.WaitforObject(By.CLASS_NAME,"Ypffh")
commentbox.click()
time.sleep(random.randint(1, 2))
#commentbox.send_keys(self.config.Random_Comment())
commentbox.send_keys("Test")
commentbox.send_keys(Keys.ENTER)
time.sleep(random.randint(3, 5))
c = c + 1
print("Liked ", c, " photos")
time.sleep(random.randint(1, 3))
它一直有效到“commentbox = self.WaitforObject(By.CLASS_NAME,"Ypffh")”,因此光标位于文本字段中。 但是当我想用“send_keys”写一些东西时,它就坏了。
确保您已从 selenium 导入密钥库
from selenium.webdriver.common.keys import Keys
使用 xpath 的查找元素(如果您使用 xpath 发送密钥,则不必先单击它)
commentbox = self.browser.find_element_by_xpath("xpath here")
commentbox.send_keys("blah blah blah")
您可能还必须单击发布按钮而不是使用 Keys.ENTER
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.