0

I am trying to write a python script using selenium to enter data into a javascript form.

I continue to get an error that the element can not be found. This is what I tried so far:

from time import sleep
from selenium import webdriver
from datetime import datetime

eGBS = "xxxxx" #removed web address b/c of company info
rpt = '' #removed web address b/c of company info
wb = webdriver.Chrome(r'C:\TEMP\chromedriver.exe')
wb.maximize_window()
wb.get(eGBS)
sleep(2)
loginClick = wb.find_element_by_link_text("Click here to login")
loginClick.click()
sleep(2)
ele1 = wb.find_element_by_id("desktop_dropdown")
ele1.click()
sleep(2)
ele2 = wb.find_element_by_id("WindowsAccountSelectId")
ele2.click()
glosub = wb.find_element_by_id("windowsSubmit")
glosub.click()
glosuccess = wb.find_element_by_id("successButtonId")
glosuccess.click()
sleep(2)
wb.get(rpt)
sleep(5) #code works to this point

# These next lines are what I have tried
#cf = wb.find_element_by_name('ff5')
#cf.click
#t = wb.find_element_by_xpath("//input[@name='ff5']")
#t.click
#ss = wb.find_element_by_xpath("//option[@value='40']") 
#ss.select
rr = wb.find_element_by_xpath("//input[@value='Run Report']")
rr.click

This is the last error I received:

Traceback (most recent call last):
  File "c:\temp\GitHub\etl\NI\eGBS_DownloadRpt.py", line 33, in <module>
    cf = wb.find_element_by_name('ff5')
  File "C:\Users\cg1262\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 496, in find_element_by_name
    return self.find_element(by=By.NAME, value=name)
  File "C:\Users\cg1262\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\cg1262\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\cg1262\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\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":"[name="ff5"]"}
  (Session info: chrome=90.0.4430.85)

This is the element I'm trying to access: enter image description here

The Gambill
  • 181
  • 1
  • 12
  • I found a similar issue [here](https://stackoverflow.com/questions/57340361/find-a-td-element-using-selenium-python) which suggest that some elements (such as iFrames, Cells, or Tables like the element you are trying to find) may not load by the time the script runs. But either way, my assumption is that because the element is a table element, find_element_by_name() might be the wrong function – Xinthral Apr 25 '21 at 14:03
  • Check if the element present inside an iframe? – KunduK Apr 25 '21 at 14:44
  • it is inside an iframe. and it is inside of a table. I tried by name and by xpath to no success... do I need to add another step here... I am also sleeping for 5 seconds to provide time for the frame to load. – The Gambill Apr 26 '21 at 14:28

1 Answers1

0

Your xpath locator is wrong in wb.find_element_by_xpath("//input[@value='Run Report']") line. We are not able to see the correct locator since you did not provide the link to the page
In case that element is inside iframe you need to switch to that iframe first.
See this post for example

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Sorry it is an internal site. However I sent the snipit of the html where I'm trying to find ff5... Run Report is one I was looking for too and it was not working but ff5 is the example I provided. – The Gambill Apr 26 '21 at 14:26
  • 1
    perfect. Thank you... I needed to switch_to.frame(frameName) – The Gambill Apr 26 '21 at 19:06