Python chromedriver不执行脚本,selenium测试在没有打印结果的情况下完成

Python chromedriver不执行脚本,selenium测试在没有打印结果的情况下完成,python,selenium,testing,selenium-chromedriver,Python,Selenium,Testing,Selenium Chromedriver,我在测试助手类中有这段代码 @staticmethod def setup_with_new_displayname(): """ Sets the application up for tests. 'execute_script' functions had to be called as a workaround because issues with the webdriver ones """ time.sleep(5) # the ne

我在测试助手类中有这段代码

@staticmethod
def setup_with_new_displayname():
    """ Sets the application up for tests. 'execute_script' functions had
        to be called as a workaround because issues with the webdriver ones
    """
    time.sleep(5)
    # the next line is where I have the problem:
    TestHelper.driver.execute_script(
        "document.querySelector('#displayname-input').value = 'gecó '")
    TestHelper.driver.find_element_by_id("displayname-input").send_keys(
        Keys.BACKSPACE)         #Workaround for the field to notice input

    # clicks the "Use this name" button
    time.sleep(1)           # otherwise the button is not always found
    TestHelper.driver.execute_script(
        "document.querySelector('#display-name-ok-btn').click()")
我有一个使用上面代码的代码:

@classmethod
def setUpClass(cls):
    """ Get the display name prompt out of the way 
        (it is tested in test_display_name_dialog.py)
    """
    TestHelper.setup_with_new_displayname()
    time.sleep(3)
我在两个地方使用了同样的second代码段,它在第一种情况下有效,但在第二种情况下(WTF?)无效。第二次打开页面和对话框时,焦点甚至放在文本输入上,光标在其中,但文本没有写在那里。(正如您在我的评论中所看到的,我以前在使用“no-execute_script”方法时也遇到过问题)

我从中运行的bash没有显示任何应该显示的测试结果,但是已经准备好执行下一个命令,该命令告诉我测试脚本已经完成(好吧,至少它这么认为)。我甚至尝试从代码中打印作为调试的一种方式-没有结果

你知道为什么会这样吗?总的来说,你有没有一个更稳定的Chrome测试方法的想法?我觉得我已经准备好抛弃Webdriver了,因为它(几乎)只会带来挫败感,现在很难看出我从中得到了什么

如果出于某种原因您希望看到更多文件,请在此处找到这些文件:

为什么要使用
execute\u脚本
?为什么不使用selenium
send_keys()
click()
?您将
send_keys()
作为一种解决方法,但这是另一种解决方法。使用
execute\u script
是一个解决办法。实际上,有一个作者的评论:“设置应用程序进行测试。execute\u script”函数必须作为一个解决办法来调用,因为webdriver onesI也有同样的问题,我在这样的论坛上发现有人说“execute\u scripts”“这是一种更可靠的方法。。。事实证明,事实并非如此。(我用send_键再次尝试了一下,结果发现它也有同样的问题——在另一个我称之为这个方法的地方,它仍然有效…)。chromedriver对其他人来说也是一个令人沮丧的来源,谷歌搜索和“堆积如山”,还是仅仅对我来说?你不应该在测试中使用execute_脚本,因为用户不会这么做。execute_脚本仅用于抓取。谢谢@pguardiario,我会尽量记住这一点:)因为它也不能与send_键一起工作,而且因为chromedriver以前工作过,我已经浪费了很多天(字面上是几天)了,我从我的项目中删除了所有selenium内容,现在尝试为我的UI测试找到一种更可预测的技术。