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.
Answer from Bilow Yuriy on Stack OverflowThank 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.

Videos
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()Try 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.
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.
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.
Use linkText element Locator method instead of XPath.
driver.get("http://awqaf.texpo.com/");
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element =wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("ABOUT US")));
// WebElement aboutdrop=driver.findElement(By.linkText("ABOUT US"));
Also, try with removing driver.switchTo().defaultContent(); this line.
Generally switchTo().defaultContent(); method is used to go back on previous working window. So if it requires in your case then & then you may use.
You are getting NoSuchElementException which generally happens in 2 cases.
Case 1: The WebElement that you are trying to find is not present (or incorrect) on the page. So check if this is correct By.xpath("//a[contains(text(),'ABOUT US')]")
Case 2: You are trying to find the WebElement even before the page has completed loaded. Which I think is your case. In this scenario you should wait for the WebElement to get completely loaded then find it.
Below is the sample code to wait for the WebElement to load.
//This will initialize a object of WebDriverWait Class with the wait time
//of 30 seconds before throwing the NoSuchElementException.
WebDriverWait wait = new WebDriverWait( driver , 30);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//a[contains(text(),'ABOUT US')]")));
Let me know if this works for you or not. Cheers.
Your xpath expression:
WebElement query = driver.findElement(By.xpath("//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input"));
looks correct but if you still are facing the issue please check the correctness of xpath again. If it fails again increase the time for Wait as:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
or you can use explicit wait for the specific element as below:
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input")));
Since you want the Polish Google site the
//input[@title='Google Search']
will not work for you. Instead use
//input[@title='Szukaj w Google']
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')]