I'm automating a service with Selenium, and the website I need to access uses iframes tags, and I need to alter the value of some elements inside this tag.
I was using the Edge WebDriver, but I changed to Chrome because I thought it'd solve the problem, and unfortunately, it didn't, so I don't think it had anything to do with the Driver, but I'd rather keep with Chrome, if possible.
This is the line that simulates the script:
gc.execute_script("""document.evaluate('//*[@id="QRYSELECT_WRK_QRYSEARCHTEXT254"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.setAttribute('value','foo')""")
And it raises me an exception about null pointers, but basically, it's saying that the browser couldn't find this element, and, therefore, couldn't change its value.
Ironically, when I open the console and write the following command (wich is the same script above):
document.evaluate('//*[@id="QRYSELECT_WRK_QRYSEARCHTEXT254"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.setAttribute('value','foo')
It works.
Here's the traceback to the error when I call execute_script from gc:
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
gc.execute_script("""document.evaluate('//*[@id="QRYSELECT_WRK_QRYSEARCHTEXT254"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.setAttribute('value','CEL_ADMITIDOS')""")
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\support\event_firing_webdriver.py", line 88, in execute_script
return self._dispatch("execute_script", (script, self._driver), "execute_script", unwrapped_args)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\support\event_firing_webdriver.py", line 160, in _dispatch
raise e
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\support\event_firing_webdriver.py", line 157, in _dispatch
result = getattr(self._driver, d_call)(*d_args)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 636, in execute_script
'args': converted_args})['value']
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'setAttribute' of null
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=71.0.3578.137 (86ee722808adfe9e3c92e6e8ea746ade08423c7e),platform=Windows NT 10.0.17134 x86_64)
So I guess it's probably something related to permissions...? But I don't know, it's quite weird to get two different results to the same script, isn't it?
Thanks!