0

i have problem when i tried to click button using selenium with webdriver Phantonjs. My code is like this :

from selenium import webdriver

driver = webdriver.PhantomJS()
driver.set_window_size(1120, 550)
driver.get("https://www.instagram.com/nike/")
dt = driver.find_elements_by_class_name("a_8imhp _glz1g")

for i in dt:
    i.click()

driver.quit()

And the error is :

  File "test.py", line 8, in <module>
    dt = driver.find_elements_by_class_name("a_8imhp _glz1g")
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 427, in find_elements_by_class_name
    return self.find_elements(by=By.CLASS_NAME, value=name)
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 782, in find_elements
    'value': value})['value']
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: {"errorMessage":"Compound class names not permitted","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"103","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:41380","User-Agent":"Python-urllib/3.6"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"class name\", \"value\": \"a_8imhp _glz1g\", \"sessionId\": \"fba6d030-4934-11e7-8712-9506860019f4\"}","url":"/elements","urlParsed":{"anchor":"","query":"","file":"elements","directory":"/","path":"/elements","relative":"/elements","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/elements","queryKey":{},"chunks":["elements"]},"urlOriginal":"/session/fba6d030-4934-11e7-8712-9506860019f4/elements"}}
Screenshot: available via screen
2
  • Can you consider updating us which button are you trying to click? Commented Jun 4, 2017 at 15:10
  • I tried to click "load more", u can see the button on instagram when u scroll down. Commented Jun 4, 2017 at 15:28

1 Answer 1

1

You cannot pass more than one class name to find_elements_by_class_name(). You can try to pass single name, e.g.

driver.find_elements_by_class_name("a_8imhp")

or to use complex selectors, e.g. XPath or CSS selector

Just replace this

dt = driver.find_elements_by_class_name("a_8imhp _glz1g")

with this

dt = driver.find_elements_by_css_selector(".a_8imhp._glz1g")

or this

dt = driver.find_elements_by_xpath("//*[@class='a_8imhp _glz1g')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.