Nosuchelementerror: Unable to Locate Element - Selenium Webdriver Using JavaScript

NoSuchElementError: no such element: Unable to locate element:

The function you're invoking are asynchronous
You click and put your driver to sleep, but the rest of the code is still executed.

Try using the await keyword if you're in an async function, or .then() to execute the rest of the code

my_function = async () => {
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
until = webdriver.until;

await driver.get('http://www.automationpractice.com');
await driver.manage().window().maximize();

await driver.findElement(webdriver.By.linkText("Sign in")).click();
await driver.sleep(10000);

await driver.findElement(webdriver.By.id("email_create")).sendKeys("natanatantsaq1w@pl.pl")
}

Check all the function you're calling to see if it returns a Promise

Unable to locate element and no such element error using Selenium and Python

Using WebDriverWait wait for element to be clickable before click on it:

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

# ...
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.LINK_TEXT, 'Customer Details'))).click()

# css selector
# wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'a[href="https://mylink"]'))).click()


Related Topics



Leave a reply



Submit