【发布时间】:2013-08-22 17:35:21
【问题描述】:
我们对使用 Python 和 Selenium 还是很陌生。所以请多多包涵。作为我们网站测试自动化工作的一部分,我们使用了一个帮助类来显示在新客户注册期间使用的验证码(效果很好)。我们现在尝试读取该值,将其保存到内存(字符串),然后将该保存的值输入到正确的页面元素中。这对我们来说是全新的,我们不知所措。这是我们目前所拥有的。
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
import urllib, urllib2
class NewAccountTests(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(5)
self.base_url = "http://www.test.com/"
self.verificationErrors = []
self.accept_next_alert = True
response = urllib.urlopen("http://www.test.com/")
htmlSource = sock.read(id = "captcha")
var.captcha = "htmlSource"
sock.close()
#SIGN UP NEW USER
def test_00_sign_up(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("name").send_keys("Foo")
driver.find_element_by_id("email").send_keys("test@me.com")
driver.find_element_by_id("screenname").send_keys("1234")
driver.find_element_by_id("password").send_keys("xxx")
driver.find_element_by_id("password2").send_keys("xxx")
driver.find_element_by_id("option1").click()
driver.find_element_by_id("option2").click()
driver.find_element_by_id("captcha").click()
>> I don't how to send the var string to the element "captcha"
driver.find_element_by_id("registration_button").click()
我确信有人很容易知道这一点,因此我们将不胜感激。
【问题讨论】:
-
@Marcin 它隐藏在代码中 :)
-
您到底想向“验证码”元素发送什么?它是一个变量吗?从哪里来?
-
我正在尝试了解如何发送
var.captcha = "htmlSource"。是的,来自def setup(self)。我不认为只使用.send_keys会在这里工作。 -
应该可以 :) 如果没有,请告诉我们!
-
不。我得到:
TypeError: read() got an unexpected keyword argument 'id'看看参数,这应该可以吗?