0

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:

ChroPathSelectors

ChroPathSelector(1)

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.

  • Ok, I tried but it doesn't work. But I am going to explain you better. In the page there are 3 "Enter" button. They are equals. The only thing that changes is the different "html address". That's why I used that type of argument for the function. – Twentymiles Oct 29 '20 at 09:32

3 Answers3

3

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.

1

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.

0

Can you try this

xpath = '//input[@value="Entra"]'
josifoski
  • 1,696
  • 1
  • 14
  • 19