This question already has answers here:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:
(9 answers)
Closed 1 year ago.
Hey guys im completely lost. I've tried everything find_by_xpath/by_class etc but it just won't work. I always get the can't find element error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ms-Button _3vq4lJQg9EQ9QnW_2iLCJo ms-Button--action ms-Button--command root-205"}
(Session info: chrome=91.0.4472.77)
next_but=web.find_element_by_id('idSIButton9')
time.sleep(1)
next_but.click()
pwin=web.find_element_by_id("i0118")
pwin.send_keys(PW)
time.sleep(2)
next_but2=web.find_element_by_id("idSIButton9")
next_but2.click()
web.get(link)
rules=web.find_element_by_class_name('ms-Button _3vq4lJQg9EQ9QnW_2iLCJo ms-Button--action ms-Button--command root-205')
I've also tried that the WebDriver waits for the element to load and it seems that the element isn't in another frame.Thats the button I'd like to be pressed
Please help me im completely lost thanks in advance
I believe this should be resolve with WebDriverWait :
Code to try it out :
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Regeln']/ancestor::button"))).click()
That's some ugly HTML. Try this:
driver.find_element_by_xpath("(//div[#data-focuszone-id='FocusZone197']/button)[4]")
Most of the HTML here looks dynamic which makes it hard to build bulletproof xpaths.
I would use the following as the aria-label should mostly stay static over time:
driver.find_element_by_xpath("(//div[#aria-label='Unterregisterkarte der Kategorie "E-Mail"']//button)[4]")
Looks like the class name you are using is dynamic. Try some thing like this
driver.find_element_by_xpath(".//button[text()='button text here']").click()
Update:
driver.find_element_by_xpath(".//span[text()='Regeln']").click()
Related
Imgur Web Element
I want to write a line of code that clicks on the ellipsis on the webpage. I've attached the element description.
I can't share the webpage as it is password protected
Here's what I tried:
element = driver.find_element_by_css_selector('.fas.fa-ellipsis-v')
element.click()
I am expecting the ellipsis to pop open but i get the following error:
Message: no such element: Unable to locate element: {"method":"css selector","selector":".fas.fa-ellipsis-v"}
First of all, please, do not use images when your want a code review or help, it is more easier to help with raw code.
In that case:
Message: no such element: Unable to locate element: {"method":"css selector","selector":".fas.fa-ellipsis-v"}
Try to use this code below instead of driver.find_element_by_css_selector([...]) :
WebDriverWait(your_driver, your_timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, your_locator)))
or
WebDriverWait(your_driver, your_timeout).until(EC.visibility_of_element_located((By.CSS_SELECTOR, your_locator)))
After the WaitDriverWait, use your find and click code.
If you need more help locating elements by, try look the Selenium Docs.
It worked by using the following line:
driver.execute_script("arguments[0].click();", element)
i have this error in selenium python
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[24]/div[1]/div/div/div[3]/div[1]/div/button[1]"}
i want the element with this xpath:
driver.find_element_by_xpath("/html/body/div[24]/div[1]/div/div/div[3]/div[1]/div/button[1]").click()
if doesn't exist, then click other element with other xpath like:
driver.find_element_by_xpath("/html/body/div[24]/div[1]/div/div/div[3]/div[1]/div/button[2]").click()
everything is clear if element 1 doesn't exists to click, click to element 2
how can I do this in selenium python
thanks
NoSuchElementException generally occurs because of one the below reasons
Element locator is incorrect
Element is not rendered
Page is not rendered or loaded
Element is inside a frame
You can have a look, do a debug and based on that write your code. :)
This is not the exact solution, but this is the idea
if elem1.is_displayed():
elem1.click()
else:
elem2.click()
I'd suggest you using time.sleep(10) and a nested try block to catch your errors while it accomplishes what you want to do. For example:
time.sleep(10)
try:
driver.find_element_by_xpath("/html/body/div[24]/div[1]/div/div/div[3]/div[1]/div/button[1]").click()
except:
print("button1 could not be found... Now trying to retreive button2")
try:
driver.find_element_by_xpath("/html/body/div[24]/div[1]/div/div/div[3]/div[1]/div/button[2]").click()
except:
print("button1 nor button2 were not found...")
Note that the time.sleep(10) delays your code from executing anything after this line for 10 seconds, and this allows the page to load properly for elements to be located easier.
Im trying to use a drop down list whit selenium :
browser.get('https://account.mail.ru/signup?from=main&rf=auth.mail.ru')
day = Select(browser.find_element_by_xpath('/html/body/div[1]/div[3]/div[3]/div/div/div/form/div[5]/div[2]/div/div[1]/div/div/select'))
dayDD=Select(day)
dayDD.select_by_index(3)
but i always get this error :
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/div[3]/div[3]/div/div/div/form/div[5]/div[2]/div/div[1]/div/div/select"}
I dont know why it can't find xpath since i get it same way i get all my other xpaths
could you attach DOM page screen with list of elements?
At this stage I see 2 posibilities:
- Elements are not loaded
Use implicit or explicit wait : https://www.geeksforgeeks.org/waits-in-selenium-python/?ref=rp
- Xpath is not correct
Maybe learn how to use relative path : https://www.tutorialspoint.com/xpath/xpath_relative_path.htm
I am trying to find an input field by Id. The input field looks like
HTML:
<input id="hgz" onkeyup="runUpKey('form_hgzii);">
Python:
driver.find_element_by_id("hgz").send_keys("test")
Result:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="hgz"]"}
While iterating through all input fields
for inputs in driver.find_elements_by_tag_name('input'):
print(inputs.get_attribute("id"))
Python prints the correct ID, when im changing the code to
for inputs in driver.find_elements_by_tag_name('input'):
if inputs.get_attribute("id") == "hgz":
inputs.send_keys("test")
it also does not work.
Anyone an Idea?
Are you running this code right after opening the page? Maybe the DOM didn't finish loading. Try putting a sleep statement like sleep(5) before trying to get element by id
I'm literally going crazy to find an element in a specific web page. It's an "Enter" button but I haven't been being able to locate it.
ERROR MESSAGE:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"input"}
(Session info: chrome=86.0.4240.111)
I'm going to share with you the possible selectors by ChroPath Extension:
HTML INSPECT CODE "ENTER" BUTTON:
<input type="button" value="Entra" onclick="parent.location.href='site.site.site'">
1°ATTEMPT - PYTHON CODE WITH REL XPATH:
elem = browser.find_element_by_xpath('//body[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[3]/td[1]/input[1]')
2°ATTEMPT - PYTHON CODE WITH ABS XPATH:
elem = browser.find_element_by_xpath('/html[1]/body[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[3]/td[1]/input[1]')
I have checked if there were any iframes, but I can't find them.
Please, help me.
I agree with #josifoski. It is better to use custom xpath than autogenerated by browser. So in your case try to use the following xpath:
xpath = '//input[#type="button"][#value="Entra"]'
It will be easier to understand and support.
I got it.
I was wrong when I told you that there weren't any iframes in the source code.
There are 2 ones!
So this is the right code to click the "Enter" button:
browser.switch_to.frame(0)
browser.switch_to.frame(1)
elem = browser.find_element_by_css_selector('td:nth-child(2) input')
elem.click()
To figure out, I recorded my steps with Selenium Ide for Chrome Browser, then I exported the python source code and I saw 2 switch_to.frame functions; then I did 2 plus 2...
Like you can see, at the end, I used a css_selector argument based on the recorded source code that I had exported.
I hope it's clear and useful for other people.
Thank you so much for your help and sorry for the incomplete information.
Can you try this
xpath = '//input[#value="Entra"]'