Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

error "Can't find form" in example. #141

Open
marunguy opened this Issue · 1 comment

1 participant

@marunguy

Below error occurred in example.

OS : Windows 7 SP1 64bit
Python : 2.7.6 32bit.
PySide : 1.2.1, PyQt : 4.10.3.
Ghost.py : trunk version

same error occurred with pyside and pyqt.

from ghost import Ghost
ghost = Ghost()
ghost.open('http://www.openstreetmap.org/')
ghost.wait_for_selector('input[name=query]')
ghost.fill("search_form", {'query': 'France'})
Traceback (most recent call last):
File "", line 1, in
File "C:\devtool\py27x86\lib\site-packages\ghost\ghost.py", line 196, in wrapper
return func(self, args, *kwargs)
File "C:\devtool\py27x86\lib\site-packages\ghost\ghost.py", line 570, in fill
raise Error("Can't find form")
Error: Can't find form

@marunguy

'http://www.openstreetmap.org/' seems to be changed.

I read documents more about ghost.py, pyside, selector.

http://jeanphix.me/Ghost.py/
http://qt-project.org/doc/qt-4.8/qwebframe.html#findFirstElement
http://www.w3.org/TR/CSS2/selector.html#q1

Above error is resolved and another error occurred.

Below is my test code, result.
After call fire_on, http error 404 returned.
What' wrong?

from ghost import Ghost
ghost = Ghost()

page, resources = ghost.open('http://www.openstreetmap.org/')
print page.http_status
print [ r.http_status for r in resources]

result, resources = ghost.wait_for_selector('input[name=query]')
print result

result, resources = ghost.fill("nav > form.search_form", {'query': 'France'})
print page.http_status
print [ r.http_status for r in resources]
print result

result, resources = ghost.fill("div > form.search_form", {'query': 'France'})
print page.http_status
print [ r.http_status for r in resources]
print result

f = open("fill.htm", "wt")
f.write(ghost.content.encode("utf-8"))
f.close()

#page, resources = ghost.fire_on("nav > form.search_form", "submit", expect_loading=True)
page, resources = ghost.fire_on("div > form.search_form", "submit", expect_loading=True)
print page.http_status
print [ r.http_status for r in resources]

f = open("fire_on.htm", "wt")
f.write(ghost.content.encode("utf-8"))
f.close()

result, resources = ghost.wait_for_selector( '#search_osm_nominatim .search_results_entry a')

ghost.click( '#search_osm_nominatim .search_results_entry:first-child a')

lat, resources = ghost.evaluate("map.center.lat")
assert float(lat.toString()) == 5860090.806537
D:\prj\secu\TestWork\ghostpy_test>ghostpy_test.py
200
[200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
 200, 200, 200, 200, 200, 200]
True
200
[]
True
200
[]
True
404
[404, 200]
Traceback (most recent call last):
  File "D:\prj\secu\TestWork\ghostpy_test\ghostpy_test.py", line 34, in <module>
    result, resources = ghost.wait_for_selector( '#search_osm_nominatim .search_results_entry a')
  File "C:\devtool\py27x86\lib\site-packages\ghost\ghost.py", line 937, in wait_for_selector
    'Can\'t find element matching "%s"' % selector)
  File "C:\devtool\py27x86\lib\site-packages\ghost\ghost.py", line 900, in wait_for
    raise TimeoutError(timeout_message)
ghost.ghost.TimeoutError: Can't find element matching "#search_osm_nominatim .search_results_entry a"

fire_on.htm's content

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head></head><body>
  <img src="/assets/osm_logo.png" style="float:left; margin:10px">
  <div style="float:left;">
    <h1>File not found</h1>  
    <p>Couldn't find a file/directory/API operation by that name on the OpenStreetMap server (HTTP 404)</p>
    <p>Feel free to <a href="http://wiki.openstreetmap.org/wiki/Contact" title="Various contact channels explained">contact</a> the OpenStreetMap community if you have found a broken link / bug. Make a note of the exact URL of your request.</p>
  </div>
</body></html>

part of source related with search_form form element.

<nav class='primary'>
      <form accept-charset="UTF-8" action="/search" class="search_form" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="HWTDRxt/elYSbk+EN/Yh+/mVO9gUQj2lnCqIQhgNE9Q=" /></div>
  <input name="commit" type="submit" value="가기" />
  <div class='query_wrapper'>
    <input id="query" name="query" placeholder="검색" type="text" />
    <a class="describe_location" href="#" title="검색 엔진을 사용하여 현재 위치를 나타냅니다">내가 어디있나요?</a>
  </div>
</form>
<div id="content" class="overlay-sidebar">
      <div id="sidebar">
    <form accept-charset="UTF-8" action="/search" class="search_form" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="HWTDRxt/elYSbk+EN/Yh+/mVO9gUQj2lnCqIQhgNE9Q=" /></div>
  <input name="commit" type="submit" value="가기" />
  <div class='query_wrapper'>
    <input autofocus="autofocus" id="query" name="query" placeholder="검색" type="text" />
    <a class="describe_location" href="#" title="검색 엔진을 사용하여 현재 위치를 나타냅니다">내가 어디있나요?</a>
  </div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.