4

I am trying to click a link by:

driver.find_element_by_css_selector("a[href='javascript:openhistory('AXS0077')']").click() 

This works nice if the link opens in a new window but in this case the link actually opens a pop up window. When I try clicking the link with this method, using selenium it gives me an error:

Message: u"The given selector a[href='javascript:openhistory('AXS0077')'] is either invalid or does not result in a WebElement. The following error occurred:\nInvalidSelectorError: An invalid or illegal selector was specified"

Is this not the right way ? because I think there may be some different way to deal with pop windows.

1
  • 2
    Try driver.find_element_by_css_selector("""a[href='javascript:openhistory("AXS0077")']""").click() or driver.find_element_by_css_selector("""a[href="javascript:openhistory('AXS0077')"]""").click()
    – falsetru
    CommentedJun 7, 2014 at 9:57

2 Answers 2

2
+50

Your css selector could be more generic, perhaps:

driver.find_element_by_css_selector("a[href^='javascript']").click() 

You've got all kinds of crazy overlapping quotation marks there. You're probably confusing it.

    0

    I have more success using find_by_xpath

    Take this site as an example popups

    I use firebug to inspect the element and get the xpath.

    Then using the following works perfectly.

    from selenium import webdriver baseurl="http://www.globalrph.com/davescripts/popup.htm" dr = webdriver.Firefox() dr.get(baseurl) dr.find_element_by_xpath("/html/body/div/center/table/tbody/tr[7]/td/div/table/tbody/tr/td[2]/div[1]/form/table/tbody/tr[4]/td[1]/a").click() 

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.