所以我对PhantomJS有一个奇怪的问题,它一直无法将文本发送到文本输入字段。当我使用chrome驱动程序运行我的代码时,没有问题,一切都按预期工作。
如果您想知道,这是抽搐流上的聊天框。这是一些代码。
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秒才能输入。使用镀铬驱动程序,打印后发送键......"大约3次,代码完成并输入消息。然而,使用PhantomJS,它会打印"发送键..."永远。
答案 0 :(得分:0)
Refind /"刷新"循环中的元素:
while not_working:
typeKeyword = browser.find_element_by_xpath('//textarea[@placeholder="Send a message"]')
...