Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Below is my script which check is element present. When I give this selector:

css=input[name='flightSearchParam[3].originAirport']

in Selenium Ide it find me this element, but when I run this in selenium rc it can't find it. I think that it is a problem with brackets.

What I must to change to find this element by selenium rc?

I run it at Windows XP and Polish Culture

Script is ready to run.

# -*- 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()

Body for :

conn.request("POST", "/selenium-server/driver/", body, headers)

 u'cmd=isElementPresent&1=css%3Dinput%5Bname%3DflightSearchParam%5B2%5D.originAirport%5D&sessionId=02b3341a3fee46f5a1e6d9c13d6e8916'

EDIT

I change it to sel.is_element_present("dom=document.getElementsByName('flightSearchParam[3].originAirport')[0]"):

and it find this element. But, I still don't know why css doesn't work here :/

share|improve this question
    
could you post your html code that you want to match – karlcow Feb 11 '11 at 4:53
    
I think you'd be better off employing a selector other than CSS (XPath, maybe?) – rs79 Feb 11 '11 at 13:45

if the HTML code is

<input name="flightSearchParam[3].originAirport">

Then the CSS Selector for it will be

css=input[name='flightSearchParam\[3\].originAirport']

You have to escape the bracket which has a specific meaning for CSS selectors.

share|improve this answer

I had a similar issue that may gain you some insight towards a solution for your problem:

Firefox Selenium IDE returned this target during a recording:

css=input[name="keywords"]

the correct CSS selector argument to obtain this element turned out to be (selenium 2.41):

solution = driver.find_element_by_css_selector('input[name="keywords"]')

So, in your case, this might work:

css= 'input[name="flightSearchParam[3].originAirport"]'
solution = driver.find_element_by_css_selector(css)

Note: in the Python Selenium, I've never needed to escape brackets which indicate indices...

share|improve this answer

Try escaping the brackets with backslashes.

share|improve this answer
    
u"css=input[name='flightSearchParam[3/].originAirport'/]" doesn't work, too – user278618 Feb 7 '11 at 14:00
    
backslashes (\), not forward slashes (/)... – ThiefMaster Feb 7 '11 at 14:34
    
sorry, I mean sel.is_element_present(u"css=input[name='flightSearchParam[3].originAirport']"‌​): doesn't work. – user278618 Feb 7 '11 at 14:46

It appears RC doesn't translate the escape sequence. I would recommend using XPath Attributes. In your case it would be -

sel.is_element_present("//input[@name='flightSearchParam[3].originAirport']")
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.