【问题标题】:Python PhantomJS Sending Keys to Text Field Not WorkingPython PhantomJS向文本字段发送键不起作用
【发布时间】: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...”。

【问题讨论】:

    标签: python phantomjs


    【解决方案1】:

    重新查找/“刷新”循环内的元素:

    while not_working:
        typeKeyword = browser.find_element_by_xpath('//textarea[@placeholder="Send a message"]')
        ...
    

    【讨论】:

    • 好的,我试试看:)
    • 原来聊天区需要adobe flash才能打字。我不知道如何让 PhantomJS 支持 flash,因为我知道他们不久前就取消了该功能。如果您有任何想法,那就太好了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 2021-08-29
    • 1970-01-01
    • 2015-08-24
    • 2015-09-23
    • 2022-08-15
    • 2015-02-04
    相关资源
    最近更新 更多