1

I am trying to locate Add button mentioned in the below HTML using

driver.find_element_by_css_selector("span.fa fa-plus").click()

<a id="ToolTables_datagrid_0" class="DTTT_button btn-primary">
  <span><span class="fa fa-plus"></span> Add</span>
</a>

It is displaying following error:

Traceback (most recent call last):   
    File "/home/vijay/PycharmProjects/practice/Menu.py", line 27, in <module>
    driver.find_element_by_css_selector(span.fa fa-plus).click() 
NameError: name 'span' is not defined

I have also tried other methods of locating the element (an Add button) but it doesn't work.

Rafayet Ullah
  • 1,108
  • 4
  • 14
  • 27
  • it sounds like python is trying to render `span` as actual python code. I don't program much in python, but if I did not know any better, I say a single quote string will fix this as it does in may languages (as opposed to your double quotes). –  Feb 25 '16 at 06:29
  • also. learn to use stackoverflow code blocks, as your HTML is not viewable without one. (stackoverflow markup will refuse to render it, if it is not in a code block –  Feb 25 '16 at 06:32
  • Thanks. But it is still displaying "TypeError: string indices must be integers" – vijaylink90 Feb 25 '16 at 06:43
  • There is an array somewhere in your code where you typed a string for the index value instead of an integer –  Feb 25 '16 at 06:46
  • here is an example of such a problem: http://stackoverflow.com/questions/6077675/why-am-i-seeing-typeerror-string-indices-must-be-integers –  Feb 25 '16 at 06:46
  • by the way did you approve my edit? –  Feb 25 '16 at 06:46
  • driver.find_element_by_name("data[User][username]").send_keys("----") driver.find_element_by_name("data[User][password]").send_keys("zaq1@wsx") driver.find_element_by_css_selector("button.btn.btn-primary").click() driver.find_element_by_link_text("Logistics").click() driver.implicitly_wait(30) driver.find_element_by_xpath(".//*[@id='left-panel']/nav/ul/li[5]/ul/li[4]/a/span").click() #import pdb; pdb.set_trace() driver.implicitly_wait(30) driver.find_element_by_css_selector('span.fa.fa-plus').click() – vijaylink90 Feb 25 '16 at 09:25
  • Yeah ..i forget to put that here while writing. – vijaylink90 Feb 25 '16 at 09:27
  • you know you can edit your post and put it in yourself. I would recommend it. I told you I do not know much python. I know a lot about programming in general, and when I looked up the error on google, I found a lot about strings can not be indexes in python –  Feb 26 '16 at 03:00

0 Answers0