Selenium/Python - 无法输入文本到用户名字段

问题描述:

我对Python和Selenium很陌生。Selenium/Python - 无法输入文本到用户名字段

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

当我在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") 
+0

如果使用FEX铬合金的开发工具检查源,你会看到你正在寻找的元素是一个嵌入式的iframe中找到。这与此类似http://stackoverflow.com/questions/15047743/selenium-webdriver-unable-to-find-element-by-id-using-python/15053287#15053287。 – TAS 2013-03-02 16:02:10

您不能输入密钥,因为它被放在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")