0

I'm trying to find a search box in some HTML and selenium won't find it.

I've tried the following.

driver.find_element_by_id
driver.find_element_by_class_name
driver.find_element_by_xpath
driver.find_element_by_css_selector

nothing has worked so far.

I've also gone line by line through the HTML and found the point where it stops picking up the elements, and in between the last one it can find and the first one it can't find is a text string as follows. (<> removed because otherwise I can't post it)

iframe id="iframeCenter" src="url initialise=true" width="100%" 
onload="resizePortlet()" frameborder="0" height="894"
/iframe

#document

!-- tabbedFindMaintenanceLayout.jsp --
html class="dj_quirks ... "/html etc

The part that says src="URL has been shortened for security reasons, but it was just the url of the web page I have active

The search button is located further down inside this HTML tag but my driver can't get there.

Here is the html of the search box

tr

td class="form_inputBoxTitle"><input type="text" name="search" size="20" 
value="" id="form_search"/td

input type="text" name="search" size="20" value="" id="form_search"

/tr

Now for my code :/

finding search box

search_box = driver.find_element_by_class_name('form_inputBoxTitle')
search_box.send_keys(phc)

finding iframe

iFrame = driver.find_element_by_id('iframeCenter')

finding html class

dj = driver.find_element_by_id('dj_quirks ')

iFrame finds the correct html tag as I would expect it to. search_box and dj both return the following error message.

search_box = driver.find_element_by_class_name('form_inputBoxTitle')
  File "C:\Users\webdriver.py", line 564, in find_element_by_class_name
    return self.find_element(by=By.CLASS_NAME, value=name)
  File "C:\Users\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "C:\Users\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such 
element: Unable to locate element: {"method":"css 
selector","selector":".form_inputBoxTitle"}
  (Session info: chrome=76.0.3809.132)

What is the issue here?

Rob_O
  • 9
  • 2
  • why don't you try to send keys to your input? Just create a custom id for your input, and then do find_element_by_id – Gergan Zhekov Sep 12 '19 at 13:43
  • I've tried using send keys but i can't find the element to being with. It's also not my site so I can't change the html – Rob_O Sep 12 '19 at 13:49
  • Also interesting note, I've loaded the page and opened the html before the box loaded and even after the box appeared the html was missing. – Rob_O Sep 12 '19 at 13:50
  • You should switch to iframe if you want to search inside an iframe - like described here: https://stackoverflow.com/questions/7534622/select-iframe-using-python-selenium Also selenium cannot find something that isn't there yet, implement some waits along the way to wait for content. – collerek Sep 12 '19 at 14:09
  • This is massive progress. I already had waits in place but usig driver.switch_to has got me much further. Not quite to the search field however – Rob_O Sep 12 '19 at 15:19
  • Going to edit my post to be more accurate as to what the issue was. Thanks all for the help – Rob_O Sep 12 '19 at 15:21

1 Answers1

0

Try this:

search_box = driver.find_element_by_id("form_search")
search_box.send_keys("foo")
Gergan Zhekov
  • 944
  • 1
  • 8
  • 27