【问题标题】:Selenium/Python - cannot input text into username fieldSelenium/Python - 无法在用户名字段中输入文本
【发布时间】:2013-07-17 18:05:37
【问题描述】:

我对 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")

【问题讨论】:

标签: python selenium


【解决方案1】:

您无法输入密钥,因为它位于 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")

【讨论】:

    猜你喜欢
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 2020-10-03
    • 2020-04-25
    • 1970-01-01
    • 2017-07-02
    • 2013-10-08
    相关资源
    最近更新 更多