下面是我的腳本,它的檢查是元素存在。當我把這個選擇:在Selenium IDE的Selenium-python中的css選擇器中括號[?]的問題
css=input[name='flightSearchParam[3].originAirport']
就找我這個元素,但是當我在硒運行這個RC不能找到它。我認爲這是括號內的問題。
我必須改變以通過硒rc找到這個元素?
我在Windows XP和波蘭文化運行
腳本就可以運行。
# -*- coding: utf-8 -*-
from selenium import selenium
import unittest, time, re
class Untitled(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 5555, "*chrome", "http://www.aa.com/")
self.selenium.start()
def test_untitled(self):
sel = self.selenium
sel.open("/international/internationalSplashAccess.do?countryCodeForIP=PL")
sel.click("localeSubmit")
sel.wait_for_page_to_load("30000")
for i in range(60):
try:
if sel.is_element_present("aa-hp-multi-city-link2"): break
except: pass
time.sleep(1)
else: self.fail("time out")
sel.click("aa-hp-multi-city-link2")
sel.click("flightSearchForm.button.reSubmit")
sel.wait_for_page_to_load("30000")
for i in range(60):
try:
if sel.is_element_present(u"css=input[name='flightSearchParam[3].originAirport']"): break
except: pass
time.sleep(1)
else: self.fail("time out")
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
機構:
conn.request("POST", "/selenium-server/driver/", body, headers)
u'cmd=isElementPresent&1=css%3Dinput%5Bname%3DflightSearchParam%5B2%5D.originAirport%5D&sessionId=02b3341a3fee46f5a1e6d9c13d6e8916'
編輯
我將其更改爲sel.is_element_present("dom=document.getElementsByName('flightSearchParam[3].originAirport')[0]"):
,並發現這個元素。但是,我仍然不知道爲什麼css在這裏不起作用:/
你可以發佈您的html代碼,你想匹配 – karlcow 2011-02-11 04:53:40
我認爲你會更好地使用除CSS以外的選擇器(XPath,也許?) – rs79 2011-02-11 13:45:14