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

标签 python selenium

我是 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/

相关文章:

java - 无法在我们只有 td 标签文本的动态表中获取元素

python - Selenium webdriver python,无法按值找到?

Python > Selenium + CSV : How to scrape from a website and write 2 columns onto CSV?

python - 检查给定整数是否等于 int 数组的两个元素之和的最佳算法是什么?

python - VSCode 无法加载 ipynb

java - 如何使用 Selenium 中字段集中的图例定位单选按钮

python - 使用 selenium python 从下拉选项中选择一个值

python - 如何覆盖 Jinja2 中的嵌套 block

Python 正则表达式 : find zip from html content

python - IB API 无法在 Mac 上正确安装