gpt4 book ai didi

python - Selenium/Python - 无法在用户名字段中输入文本

转载 作者:太空宇宙 更新时间:2023-11-03 14:28:51 26 4
gpt4 key购买 nike

我是 Python 和 Selenium 的新手。

我正在尝试创建一个自动脚本,其中加载页面并完成用户名和密码字段。

当我在 Selenium 中运行自动化时,它工作正常(这是一个简单的过程),但是当我通过 python 服务器运行它时它不起作用。页面加载,但未填充任何字段。

感谢任何帮助!

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re

class Pageload(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://gymbox.com/"
self.verificationErrors = []
self.accept_next_alert = True

def test_pageload(self):
driver = self.driver
driver.get(self.base_url + "/Login")
driver.find_element_by_id("login_Email").clear()
driver.find_element_by_id("login_Email").send_keys("hello")

最佳答案

您不能输入 key ,因为它放在 iframe 中。尝试 driver.switch_to_frame() 然后执行其余脚本。

这里是例子:

def test_pageload(self):
driver = self.driver
driver.get(self.base_url + "/Login")
driver.switch_to_frame('iframe') #<iframe> is the ID of your iframe
driver.find_element_by_id("login_Email").clear()
driver.find_element_by_id("login_Email").send_keys("hello")

关于python - Selenium/Python - 无法在用户名字段中输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15176373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com