Selenium is unable to find an element on a webpage, here is the python code
element = driver.find_element(By.CLASS_NAME, "_13NKt copyable-text selectable-text")
Here is an image of the element it is supposed to find, class highlighted
And here is the important line of the error message:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"._13NKt copyable-text selectable-text"}
(Session info: chrome=103.0.5060.134)
You have to take care of a couple of things here:
By.CLASS_NAME
accepts only one argument. So you won't be able to pass multiple classes._13NKt
are dynamically generated and is bound to chage sooner/later. They may change next time you access the application afresh or even while next application startup. So can't be used in locators.<div>
is having the attribute contenteditable="true"
.To identify the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-testid='pluggable-input-body'][role='textbox']")))
Using XPATH:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@data-testid='pluggable-input-body' and @role='textbox']")))
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC