The problem with brackets [?] In the css selector in Selenium-python

Below is my script that checks for the presence of an element. When I give this selector:

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

in Selenium. Look for this element, but when I run it in selenium rc, it cannot find it. I think this is a problem with brackets.

What do I need to change to find this selenium rc element?

I run it on 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 find this item. But I still don't know why css is not working here: /

+5
source share
4 answers

if the HTML code

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

Then for this CSS selector there will be

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

, CSS.

+2

, :

Firefox Selenium IDE :

css=input[name="keywords"]

CSS ( 2.41):

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

, :

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

: Python Selenium , ...

+1

Try to avoid parentheses with backslashes.

0
source

RC doesn't seem to translate the escape sequence. I would recommend using XPath attributes. In your case it will be -

sel.is_element_present("//input[@name='flightSearchParam[3].originAirport']")
0
source

All Articles