1

I'm trying to fill the forms of these page, I checked the HTML code and the forms that I'm looking for are there but when I run my code, I got an error that I never seen in selenium.

I'm using PhantomJS 2.1.1 in Python 3.6.1 with Selenium.

I Want to fill these form.

<input type="text" name="Dt_Ref" value="31/08/2017" maxlength="10" size="10" class="form_data" onBlur="formatCamp(this, 'date');javascript:if(REUNE.Dt_Ref.value!=REUNE.Dt_RefAnt.value){REUNE.target='_self';REUNE.action='reune.asp';REUNE.submit()};" onKeyPress="return(validaConteudo(event, this, 'date'))" onKeyUp="saltaCampo(event, this, 'date',8)" onFocus="removeCaracs(this, 'date')">  <a style="cursor:hand; cursor:pointer;" onclick="openCalendar(document.REUNE.elements['Dt_Ref']);return false;">

My Code is:

from selenium import webdriver


url = 'http://www.anbima.com.br/reune/reune.asp'
path_phantom = 'C:\\Users\\TBMEPYG\\AppData\\Local\\Continuum\\Anaconda3\\Lib\\site-packages\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe'

#Processing

driver = webdriver.PhantomJS(executable_path= path_phantom)
driver.get(url)
name = driver.find_element_by_name("Dt_Ref")
driver.quit()

And I got this error:

Traceback (most recent call last):
  File "C:\Users\TBMEPYG\Desktop\beta_anbima.py", line 11, in <module>
    name = driver.find_element_by_name("Dt_Ref")
  File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 426, in find_element_by_name
    return self.find_element(by=By.NAME, value=name)
  File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 832, in find_element
    'value': value})['value']
  File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
  File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: {"request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"89","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:64945","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"name\", \"value\": \"Dt_Ref\", \"sessionId\": \"cc170460-8e5e-11e7-ad22-8d3d940cf70e\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/cc170460-8e5e-11e7-ad22-8d3d940cf70e/element"}}
Screenshot: available via screen

This is the first step of my code. I'm under a bank proxy and this could be the problem. When I access from my Chrome, the page works fine. When I try to use the same code (changing the url and the element name) in this site, it works fine.

Thank you all.

7
  • Works fine with Chrome on windows. Commented Aug 31, 2017 at 15:37
  • Any ideia about why this doesnt work on phantomJS? My network is restricted and I cant download the Chrome's web driver Commented Aug 31, 2017 at 15:42
  • No idea, try with Firefox if you have the driver. Commented Aug 31, 2017 at 15:48
  • I don't have too. It has to be with phantomJS ): Commented Aug 31, 2017 at 17:12
  • Try to select the element by xpath. See if it works. Commented Aug 31, 2017 at 17:22

1 Answer 1

1

This is an issue/bug with PhantomJS.

I would suggest you use Chrome as such or docker image for selenium/standalone-chrome

If you look at https://github.com/ariya/phantomjs/issues there are 1923 open issues, which speaks for itself.

You can't even query

driver.find_elements_by_xpath("//*")

You will get the error

NoSuchElementException: Message: {"request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"87","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:53425","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"xpath\", \"value\": \"//*\", \"sessionId\": \"eb09e680-8e72-11e7-8b72-d1137b47fa59\"}","url":"/elements","urlParsed":{"anchor":"","query":"","file":"elements","directory":"/","path":"/elements","relative":"/elements","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/elements","queryKey":{},"chunks":["elements"]},"urlOriginal":"/session/eb09e680-8e72-11e7-8b72-d1137b47fa59/elements"}}
Screenshot: available via screen

So open a bug and make the count 1924, but I really doubt you would get much help

Sign up to request clarification or add additional context in comments.

3 Comments

Understood. Is there any possibility of using chrome as a headless browser?
Yes you can use that by creating ChromeOptions. Also use headless only if it works, i have seen other issues with headless where it is not same as chrome, some websites not working fine. So check if yours work and if it works then use it.
@ThalesMarques Read this intoli.com/blog/running-selenium-with-headless-chrome . From what I have heard with new headless, you can't use extensions. An easier way is just to use chrome options though if you have linux it is better to run it the headless through the most recent Chrome rather than chrome options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.