1

I am trying to create a script within Python using Selenium to open a social media page (Tumblr), input user login credentials, and make "quote" posts with a random sentence generator. I am able to input the credentials and select the create post icon using xpaths (driver.find_element_by_xpath) from the website, but when trying input text for the post with the xpath

//*[@id="redpop_iframePostForms"]/div[3]/div/div/div/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div/div[1]/p

using the

self.driver.find_element_by_xpath('//*[@id="redpop_iframePostForms"]/div[3]/div/div/div/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div/div[1]/p').send_keys("It worked!!")

I receive the error

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id="redpop_iframePostForms"]/div[3]/div/div/div/div/div[2]/div[2]/div/div[2]/div/div[1]/div/div/div[1]"}

I have tried using the other div classes within the list of divs, but I cannot find the correct one. I have also tried using the CSS selector with the code

driver.find_elements_by_css_seletor("div[@aria-label='Quote']").send_keys("It worked!!!")

but that provided the error

Message: invalid selector: An invalid or illegal selector was specified

Any direction on where to go from here?

Thanks!

0

1 Answer 1

1

For no such element exception

From your xpath, i can guess that element is present in an iframe. First switch to that frame and then find element you want to interact with.

For invalid selector message

General Syntax for locating element with css selector is :

tagname[attributeName=‘attributeValue’]

You don’t need to use @ with attributeName. Also, you are fetching all the div elements present in the DOM with aria-label=‘Quote’ and sending keys which is not right. If you want to perform any action on elements, you need to put them in list and then iterate over it. Hope this helps.

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.