【发布时间】:2015-05-31 05:48:41
【问题描述】:
所以我在使用 PhantomJS 时遇到了一个奇怪的问题,它不断无法将文本发送到文本输入字段。当我使用 chrome 驱动程序运行我的代码时,没有问题,一切都按预期工作。
如果您想知道的话,这是 twitch 流上的聊天框。这是一些代码。
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,它会永远打印“Sending keys...”。
【问题讨论】: