You aren't using the same CSS selector in both instances. Change
[name-firstName]
to
[name='firstName']
in the second instance.
Also, your code looks overly complicated. Have you tried something like this?
Answer from JeffC on Stack OverflowYou aren't using the same CSS selector in both instances. Change
[name-firstName]
to
[name='firstName']
in the second instance.
Also, your code looks overly complicated. Have you tried something like this?
When you've a name attribute, you can use
driver.get("www.examplewebsiteonly.com")
.then(function() {
return driver.wait(until.elementLocated(By.name("firstName")), 20000)
.then(function(){
driver.sleep(20000)
.then(function(){
return driver.findElement(By.name("firstName")).sendKeys("FirstName");
})
})
})
I replaced the css selector with the name selector that Selenium provides. Also single quotes removed to add double quotes.
NoSuchElementError: Unable to locate element - Selenium webdriver using Javascript - Stack Overflow
NoSuchElementException: no such element: Unable to locate element
I got Unable to locate element error
NoSuchElementError: no such element: Unable to locate element:
How do you fix no such element exception in Selenium?
How to Fix NoSuchElementException in Selenium
Why Does Selenium Throw a NoSuchElementException?
Videos
"NoSuchElementError" suggests that the element is not present (yet) in the HTML document. This can occur when some elements appear/disappear dynamically. When your Selenium scripts run faster than the element loads, the element is not visible yet and this error will be thrown.
In your case, does the element input#FirstName appear only after input#FirstName has been clicked?
If so, consider adding a pause or wait function in between createAcc() and firstName()
Put a closing brace to close your "locators" object (syntax error)
Hi,
I'm very new to selenium and writing my first script which is a Google search. Th script has trouble clicking on the search button after typing in what to search for. I get a 'NoSuchElementException: no such element: Unable to locate element'. I also changed the script so it presses enter rather than clicking on the button and got the same error. Can you help? I have placed links to screenshots of my code and the error.
https://imgur.com/a/TeNy66B
Thanks
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("[email protected]")
}
Check all the function you're calling to see if it returns a Promise
The id is not matching to email input field, try this,
var emailInput = driver.findElement(webdriver.By.id("//input[@name='email']"));
emailInput.sendKeys("[email protected]");
Looks like it takes time to load the webpage, and hence the detection of webelement wasn't happening. You can either use @shri's code above or just add these two statements just below the code driver = webdriver.Firefox():
driver.maximize_window() # For maximizing window
driver.implicitly_wait(20) # gives an implicit wait for 20 seconds
Could be a race condition where the find element is executing before it is present on the page. Take a look at the wait timeout documentation. Here is an example from the docs
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("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "myDynamicElement"))
)
finally:
driver.quit()
I am attempting to write a simple web automation script, but part of it involves attempting to click a nonexistent button until it appears.
I was able to do this in python with this code:
while True:
try:
driver.find_element_by_xpath('').click()
break
except NoSuchElementException:
pass
except ElementNotInteractableException:
pass
But I am unable to do that in node. This is the error I get:
(node:1544) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element:
How would I be able to do that with node js?
After you clicked loginenter button, some wait should be added to reload page. It will provide small delay which is helpful for SeleniumDriver to identify element. I would like to suggest you to add some condition to wait next element. Please try below code snippet
WebElement myDynamicElement =
(new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("usrUTils")));
You should wait for page load after click on button,so for that write below code :
WebElement element;
Webdriver driver;
WebDriverWait wait = new WebDriverWait(driver, 100);
element= wait.until(ExpectedConditions.elementToBeClickable(By.id("usrUtils")));