Induce WebDriverWait and elementToBeClickable to click on the element.

Try the following options.

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement selectGender = wait.until(ExpectedConditions.elementToBeClickable(By.id("id_gender1")));
selectGender.click()

OR

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement selectGender = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='radio-inline']/label[@for='id_gender1']")));
selectGender.click()
Answer from KunduK on Stack Overflow
🌐
GitHub
github.com › eddyharrington › WhatSoup › issues › 3
Message: no such element: Unable to locate element: {"method":"css selector","selector":"span"} · Issue #3 · eddyharrington/WhatSoup
March 8, 2021 - Message: no such element: Unable to locate element: {"method":"css selector","selector":"span"}#3 · Copy link · Assignees · Labels · bugSomething isn't workingSomething isn't working · oddtazz · opened · on Mar 8, 2021 · Issue body actions · I ran into this issue on Windows as well as osx ·
Author   oddtazz
Discussions

no such element: Unable to locate element: {"method":"css selector","selector":".jobs-search-results"}
Describe the bug The bot logins to LinkedIn but never applies for jobs or even searches for the criteria not sure what is happening. Screenshots Error Statement Message: no such element: Unable to locate element: {"method":"css selector"... More on github.com
🌐 github.com
6
August 29, 2022
python - Selenium Issue - Unable to locate element: {"method":"css selector","selector" - Need help fixing this - Stack Overflow
I need to fix this code. This comes with an error message saying NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","sele... More on stackoverflow.com
🌐 stackoverflow.com
Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“.syllable”}

Can you tell the website and what you wanna scrape?

More on reddit.com
🌐 r/learnpython
3
1
July 27, 2021
python - NoSuchElementException: no such element: Unable to locate element: css selector but im using find_element - Stack Overflow
I used selenium IDE to trace my UI activity. I got this following code from IDE and i inspected in UI also,but while using find_element by id i'm getting css selector error. driver.find_element(By... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › nicolomantini › LinkedIn-Easy-Apply-Bot › issues › 102
no such element: Unable to locate element: {"method":"css selector","selector":".jobs-search-results"} · Issue #102 · nicolomantini/LinkedIn-Easy-Apply-Bot
August 29, 2022 - Error Statement Message: no such element: Unable to locate element: {"method":"css selector","selector":".jobs-search-results-list"} (Session info: chrome=104.0.5112.102)
Author   mrtknrt
🌐
Reddit
reddit.com › r/learnpython › message: no such element: unable to locate element: {“method”:“css selector”,“selector”:“.syllable”}
r/learnpython on Reddit: Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“.syllable”}
July 27, 2021 -

I want to get words from a site using selenium on python. Is there any way to do it? I've tried Xpath, class name and still nothing.

driver.find_element_by_class_name('syllable') driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/div[2]/div')

<div class="round"> <div class="syllable">gi</div> </div> So I want to get "gi". Thanks!

Top answer
1 of 2
5

It is important to see what you've tried and what problems did you have, but, judging by what was provided in the question, here is how you can locate the element by "name", by a "CSS selector" and by an "Xpath expression":

driver.findElement(By.name("amount")); 
driver.findElement(By.cssSelector("input[name=amount]"));
driver.findElement(By.xpath("//input[@name='amount']"));

Possible issues:

  • check if an element is inside an iframe or not - if it is, you'll need to switch to the context of the frame and only then find the element
  • timing issue - the element might not be present when you are searching for it. In this case, use an Explicit Wait to wait for the element to be present
2 of 2
1

Firstly you have to look that whether element is present is any Frame. If the element is there in any Frame then you have to switch into that particular Frame by using below syntax:

driver().switchTo().frame("frameName");
driver().switchTo().frame("frameIndex");

You can also switch to the frame by giving its element like class, id etc.

driver().switchTo().frame(findElementByClassName("shrGoogleConnectIframe"));

Then you can locate the element using its any of the property mentioned.

driver.findElement(By.name("amount"));
driver.findElement(By.cssSelector("input[name=amount]"));
driver.findElement(By.xpath("//input[@name='amount']"));

Once you are able to locate the element, you have to switch back to the default content using below syntax:

driver.SwitchTo().DefaultContent();

In test automation services, the best practice is to use id, name and CSS selectors, Xpath should be given least priority.

Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › selenium can't find the element i'm searching for
r/learnpython on Reddit: Selenium can't find the element I'm searching for
February 26, 2020 - It seems that I found everything I needed using a Chrome Extension called Element Locator. I used the find_element_by_css_selector method on all of my values and it works like a charm, except for one. I tried getting the xpath as an alternative, but I always get an error that it didn't find the element: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"div#bcp-06d2d > div > app-employee-profile-category-form > app-employee-tables > app-employee-tables-summary > div > b-display-field-value:nth-of-type(4) > span"} (Session info: chrome=80.0.3987.122)
🌐
Educative
educative.io › answers › what-is-nosuchelementexception-in-selenium-python
What is `NoSuchElementException` in Selenium-Python?
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="userNam"]"}
🌐
Selenium
selenium.dev › documentation › webdriver › troubleshooting › errors
Understanding Common Errors | Selenium
You may have used a CSS or XPATH selector as a parameter to an ID selector. ... The element can not be found at the exact moment you attempted to locate it.
🌐
GitHub
github.com › eddyharrington › WhatSoup › issues › 1
Unable to locate element: {"method":"css selector","selector":"._3Tw1q"} · Issue #1 · eddyharrington/WhatSoup
February 27, 2021 - Traceback (most recent call last): ... stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"._3Tw1q"} (Session info: chrome=87.0.4280.66)...
Author   kannadivinorum
🌐
Reddit
reddit.com › r/selenium › hi why do i get this error? (selenium & python)
r/selenium on Reddit: Hi Why do I get this error? (selenium & python)
February 19, 2018 -

hi guys why do I get this error?

    selenium.common.exceptions.NoSuchElementException:         
    Message: no such element: Unable to locate element: 
    {"method":"name","selector":"user_name"}


   Here is the "inspect code":
   <input name="user_name" id="user_name" type="text" 
   class="form-control" value="" autocomplete="off">


  and here is my python code:
  from selenium import webdriver from selenium.webdriver.common.keys import Keys
  driver = webdriver.Chrome(')
  driver.get("https://mobilitie.service-now.com/")
  search = driver.find_element_by_name("user_name")

Im sorry, this is a stupid question but I was trying to figure this out for hours now :(

🌐
GitHub
github.com › joeyism › linkedin_scraper › issues › 184
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".name"} · Issue #184 · joeyism/linkedin_scraper
July 15, 2023 - unable to scrape companies with latest version, receiving this error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".name"} code: driver = webd...
Author   vastoutreach
🌐
Google Groups
groups.google.com › g › selenium-users › c › XPvLw3CHpfg
Selenium WebDriver: Unable to Locate the Element by CSS
What happens when you use any of the other CSS selectors previously mentioned? Can you locate them but clicking clicks on the "wrong" element? When Webdriver clicks on an element it clicks on the screen in the "middle" of the element. So, if it overlaps with other elements and they are on top of it at the middle point, the foremost element will get clicked. If you need to click such a partially hidden element, you'll have to use the .moveByOffset() method, which I think is part of the Actions class and you can find examples of its use in previous threads on the forum.