0

How can I click on this element using selenium? I was tried using:(but was not successful)

divselected = driver.find_element_by_css_selector(div[aria-label="Add a public comment..."])

divselected.click()

I also tried

divselected = driver.find_element_by_id("contenteditable-root")
divselected.click()

The div I am trying to click:

<div id="contenteditable-root" contenteditable="true" dir="auto" class="style-scope yt-formatted-string" aria-label="Add a public comment..."></div>'
josephf
  • 1
  • 1

3 Answers3

0

Hope this help:

divselected=driver.find_element_by_xpath("//*[contains(text(),'Add a public comment')]")
Amruta
  • 1,128
  • 1
  • 9
  • 19
  • I get the following: driver.find_element_by_xpath(//*[contains(text(),'Add a public comment')]) ^ SyntaxError: invalid syntax – josephf May 08 '20 at 16:29
  • Updated code ..forgot to put double quotes.it should work now and it will return one matching element. – Amruta May 09 '20 at 01:02
0

The following code works:

divselected = driver.find_elements_by_xpath("//*[contains(text(), 'Add a public comment...')]")

divselected[0].click()
josephf
  • 1
  • 1
0

try using

driver.find_element(By.ID, 'contenteditable-root').click()

or instead of ID use Class Name.

Harsh Mangalam
  • 1,116
  • 1
  • 10
  • 19
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 14 '23 at 18:58