Try using CSS
WebElement element = new WebDriverWait(driver,30).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[id*='DERIVED_REGFRM1_LINK_ADD_ENRL'][class='SSSBUTTON_CONFIRMLINK']")));
Answer from Yuvaraj HK on Stack OverflowTry using CSS
WebElement element = new WebDriverWait(driver,30).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[id*='DERIVED_REGFRM1_LINK_ADD_ENRL'][class='SSSBUTTON_CONFIRMLINK']")));
It's possible the page object has not loaded at the time Webdriver is searching for it. Try to locate the step that is failing, and place an implicit wait/sleep before it.
If Webdriver is able to find the page object after you know it's a page load issue.
- Identify the step the test is failing on.
- Place a Wait/Sleep before the step ie... 20 seconds (way more than enough).
- Execute your test again.
- If the test now passes, Webdriver searched for the page object before it fully loaded.
Selenium can't locate element by xpath - Software Quality Assurance & Testing Stack Exchange
Can't get element by XPATH
Cannot find element by XPATH although it is there.
automated testing - Unable to locate element using XPath getting NoSuchElementException - Software Quality Assurance & Testing Stack Exchange
Videos
Thank you for all answers. I found solution to my problem. The last command was command which was linked with IFrame
WebElement editorFrame = driver.findElement(By.cssSelector("#sentmsgcomposeEditor_ifr"));
driver.switchTo().frame(editorFrame);
WebElement body1 = driver.findElement(By.tagName("body"));
body1.sendKeys(Keys.CONTROL + "a");
So i was in IFrame actually because of it i couldn't find any element. I performed following command:
driver.switchTo().defaultContent();
After that it is possible to find locators.
You should try to locate by id instead of by xpath.
driver.findElement(By.id("folder0")).click();
Two reasons:
- Locating by id is usually faster (see here for why).
- Since you're trying to test the link, you don't need to click on an inner
<span>, just on the link element itself.
If you still want to use xpath, or still want to get the inner <span>, you can use firebug in Firefox to copy the xpath; this will give you the correct xpath and show you if you made a mistake.

NoSuchElementException happens generally in 2 scenarios.
- Webelement locator is wrong. (which doesn't seems to be the situation in your case)
- Your are trying to find the webelement even before it is loaded on the page.(This seems to be your problem)
To solve this you should wait till the webelement gets loaded on to the webpage.
One way to do this to use WebDriverWait Class. Sample snippet is below:
/* Initialize the WebDriverWait, with 30 seconds of wait time. */
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("locator_name")));
There might be another reason why you get NoSuchElementException: you are not in the correct iframe. If your element is inside an iframe, you must "move" to it. See https://stackoverflow.com/questions/44834358/switch-to-an-iframe-through-selenium-and-python for an answer in python.
Hello guys,
I'm trying to interact with the interative menu of this page in order to automate several data downloads instead of making it by hand.
The thing is that when I copy an XPATH of a selector (for example when I try to get the XPATH of the "Commodities" menu), selenium says:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[9]/div[1]/div[3]/ul/li[6]"}
Does anyone know why I can't get the element?
Thank you all in advance!
EDIT WITH SOLUTION:
The problem was that items I want to find are inside an iframe. So I have to switch the context of the webdriver first. Code with the solution:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://www.dukascopy.com/swiss/english/marketwatch/historical/')
table = driver.find_element(By.XPATH, '/html/body/div/main/div[2]/div/div/div/p[3]/iframe')
driver.switch_to.frame(table)
driver.find_element(By.XPATH, '/html/body/div[9]/div[1]/div[3]/ul/li[13]').click()Hey guys, new to the community and new to using Selenium. Can I please have some help? I am using Python and Selenium for navigating through a website. The website is turo.com; my goal is to login using my code.
So far, I am able to open the website, navigate to the "log in" button and click on it. After the login button is clicked, there is a modal that pops up with 2 input fields for email/user and password. I have the XPATH to the input fields but they are not working. I get the following error message:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"html/body/div[1]/form/div[1]/input[@id="email"]"}
Please let me know how to debug this error. I have tried stackoverflow and other forums but no answer so far. Thank you!
EDIT: I have tried using '//input[@data-testid="email"]' as well.
Switch to the iframe first, for that try the below code.
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[src*=sfactory]")));
After that you can use the XPath or CSS selector to identify the locator.
css: a[onclick*=exitAction]
xpath: //a[contains(@onclick, 'exitAction')]
Try with the below xpath.
//a[contains(text(),'Logout')]
Make sure you are using the correct X Path.
Use the following link to get perfect X Paths to access web elements and then try.
Selenium Command
Hope this helps to solve the problem!
Try a different XPath. I've verified this is unique on the page.
driver.find_element_by_xpath("//a[contains(.,'following')]")