1

I'm new to automation testing and decided to use Tumblr as my subject. I'm having trouble making the options appear, see image attached, and don't know what else to use.

enter image description here The code I'm currently trying to run it to is:

driver.find_element_by_xpath("//div[@class='dropdown-area icon_arrow_carrot_down']").click()

I've also tried

find_element_by_class_name 
find_element_by_class_id 
implicitly wait 

still get the same error.

Below is the error I'm getting.

Traceback (most recent call last):

File "C:\Users\pmevangelista\eclipse-workspace\Pytest\python1\PySel.py", line 37, in driver.find_element_by_xpath("//*[@class='dropdown-area icon_arrow_carrot_down']").click()

File "C:\Users\pmevangelista\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 365, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\pmevangelista\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 855, in find_element 'value': value})['value']
File "C:\Users\pmevangelista\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute self.error_handler.check_response(response)
File "C:\Users\pmevangelista\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@class='dropdown-area icon_arrow_carrot_down']"} (Session info: chrome=62.0.3202.94)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64)

Thank you in advance for your help.

  • How about using div.dropdown-area.icon_arrow_carrot_down as css locator? It can be done using the find_element_by_css_selector [I think - it's been a long time since I used Python.] – demouser123 Nov 24 '17 at 15:55
  • @demouser123 Yes!! This works! Thank you so much! – Ice Nov 27 '17 at 1:31
  • Glad it worked. – demouser123 Nov 27 '17 at 15:59
1

I think at least one of the problems is that there are more class values on this element and you are checking only part of the class which leads to the element not found error. This element looks this way on my end (see that pinned-target part you've missed):

<div class="dropdown-area icon_arrow_carrot_down pinned-target" data-js-clickablesavedropdown=""></div>

I would instead use a CSS selector which is more concise and deals with multi-valued attributes like class much easier. One possible way to locate the element would be to use the preceding Post button:

driver.find_element_by_css_selector("button.create_post_button + .dropdown-area")

Or, the parent "save post" container:

driver.find_element_by_css_selector(".post-form--save-button .dropdown-area")

Note that to make things more reliable and to eliminate one other possible reason for the error, add an Explicit Wait for presence, visibility or clickability of the element:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Firefox()
driver.get("url")

wait = WebDriverWait(driver, 10)
dropdown = wait.until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, ".post-form--save-button .dropdown-area"))
)
dropdown.click()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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