Python PhantomJS向文本字段发送键不起作用

2024-09-30 01:37:51 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我在PhantomJS中遇到了一个奇怪的问题,它总是无法将文本发送到文本输入字段。当我用chrome驱动程序运行代码时,没有问题,而且一切都按预期工作。在

如果你想知道的话,这是twitch streams上的聊天框。这里有一些代码。在

print("Finding chat box...")
typeKeyword = wait_until_visible_by_xpath('//textarea[@placeholder="Send a message"]', browser)
not_working = True
while not_working:
    try:
        print("Sending keys...")
        typeKeyword.send_keys("hi")
        not_working = False
    except InvalidElementStateException:
        sleep(3)
print("Hitting chat button")
chatButton = wait_until_visible_by_xpath('//button[@class="button send-chat-button primary float-right"]', browser)
chatButton.click()

PhantomJS能够定位文本字段,但在检查是否可以发送密钥时,它总是被困在InvalidElementStateException上。应该有一个小的延迟,因为抽搐聊天框通常是灰色的6-10秒,然后它可以进入它。使用chrome驱动程序,在打印“Sending keys…”大约3次后,代码结束并键入消息。然而,对于PhantomJS,它会永远打印“发送密钥…”。在


Tags: 代码文本驱动程序chatnotbuttonkeysphantomjs

热门问题