因此,我在使用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上。应该有一个小的延迟,因为twitch聊天框通常会灰显6-10秒,然后才能在其中键入内容。使用chrome驱动程序,在打印“发送密钥...”之后大约3次,代码结束并输入消息。然而,对于PhantomJS,它会打印“正在发送密钥...”永远不变。
发布于 2015-05-31 05:48:41
Refind/“刷新”循环中的元素:
while not_working:
typeKeyword = browser.find_element_by_xpath('//textarea[@placeholder="Send a message"]')
...https://stackoverflow.com/questions/30551448
复制相似问题