如何修复使用VNC用Selenium呈现完整HTML页面的问题

2024-09-30 14:36:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用前端VueJS来设计我的网页和seleniumhub来测试我的前端。对于后端,我使用Django。所有这些都在我的码头上。 我在下面的URL中有多个名为WJLoginWJHeaderWJFooter的VueJS组件:“http://backend:8001/account/login”。除了VueJS的所有组件的元素外,该URL的所有元素都会加载。对于这个问题,我倾向于WJLogin,因为如果一个组件确实加载了,那么其他组件也会自动加载(如果一切都相同)

我尝试了以下选项:

  • 通过这个命令打印整个源代码print(driver.page_source)这个结果表明WJLogin没有被加载

  • 重新启动整个docker

我的测试文件中的代码tests_frontend.py

class AccountTestCase(unittest.TestCase):

    def setUp(self):
        caps = {'browserName': 'chrome'}
        url = 'http://selenium_hub:4444/wd/hub'

        self.browser = webdriver.Remote(
            command_executor=url,
            desired_capabilities=caps
        )

    def tearDown(self):
        self.browser.quit()

    def test_login(self):
        driver = self.browser
        driver.get("http://backend:8001/account/login")
        print(driver.page_source)

来自我的VueJS文件的代码WJLogin.vue(这是我的组件)

<template>
    <div>
        <v-app>
            <WJHeader :username="username"></WJHeader> 
                <v-layout align-center justify-center row>                  
                    <v-flex lg5>
                        <v-container white>
                            <form method="post" action="/login_view">
                                <h4>Login into <span class="primary--text"> Phoenix </span></h4>
                                <input name="csrfmiddlewaretoken" :value="csrf" type="hidden">
                                <v-text-field id="loginUsername" name="username" label="Username" required> </v-text-field>

                                <v-text-field
                                :append-icon="showPassword ? 'visibility' : 'visibility_off'"
                                :rules="[passwordRules.required]"
                                :type="showPassword ? 'text' : 'password'"
                                label="Password"
                                name="password"
                                id="loginPassword"
                                @click:append="showPassword = !showPassword">
                                </v-text-field>

                                <v-btn id="loginSubmit" color="success" type="submit"> Login </v-btn>
                                <v-btn color="error" type="reset"> Reset </v-btn>
                            </form>
                        </v-container>
                    </v-flex>

                </v-layout>
            <WJFooter></WJFooter>
        </v-app>
    </div>
</template>

此屏幕截图显示输出

enter image description here

此屏幕截图显示源代码(Ctrl+U)

enter image description here

这个屏幕截图显示了元素(F12 -> inspector)

enter image description here

当我去我的网页没有硒,我可以看到WJLogin没有问题

我希望Selenium必须加载WJLogin组件,就像正常模式一样(没有Selenium和正常的chrome/firefox浏览器)

注意:在StackOverflow上发布图片需要10点声望


Tags: textselfhttp元素fieldtypedriver组件