Website automate detecting and click a button error?

This is the place for queries that don't fit in any of the other categories.

Website automate detecting and click a button error?

Postby Poppins586 » Fri Apr 25, 2014 5:57 pm

Here is an example website that I am trying to access with Python automatically. (http://www.waynecoun...heriff/1359.htm)



The problem here is that the url doesn't change at all, which means that it's probably running its own program behind the scenes. I need to automatically detect and click the accept button. Furthermore, at the next part, I need to detect the last name and first name part of the following webpage. From that point, I need to then insert the raw_input('last name: '), raw_input('first name: ') in the appropriate spots. Then, to make it even more complex, I need to click on the more info buttons associated with that particular inmate so I can find the text (which needs to be ordered as well) so I can find out their charges and their bond information which needs to be sent back to the program.



I've tried-

Code: Select all
import splinter
import selenium
from splinter import Browser
with Browser() as browser:
   browser.visit('http://www.waynecounty.com/sheriff/1359.htm')
   browser.find_by_name('Accept').click()

Traceback (most recent call last):
  File "<pyshell#14>", line 3, in <module>
    browser.find_by_name('Accept').click()
  File "C:\Python27\lib\site-packages\splinter\element_list.py", line 75, in __getattr__
    self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'click'

import time

with Browser() as browser:
   browser.visit('http://www.waynecounty.com/sheriff/1359.htm')
   time.sleep(10)
   browser.find_by_name('Accept').click()

   

Traceback (most recent call last):
  File "<pyshell#27>", line 4, in <module>
    browser.find_by_name('Accept').click()
  File "C:\Python27\lib\site-packages\splinter\element_list.py", line 75, in __getattr__
    self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'click'

from selenium import webdriver

def SearchWayne(url):
   driver = webdriver.PhantomJS()
   driver.set_window_size(1024,768)
   driver.get(url)
   driver.save_screenshot('screen.png')
   sbtn = driver.find_element_by_css_selector('Accept')
   sbtn.click()

SearchWayne('http://www.waynecounty.com/sheriff/1359.htm')

Traceback (most recent call last):
  File "<pyshell#37>", line 1, in <module>
    SearchWayne('http://www.waynecounty.com/sheriff/1359.htm')
  File "<pyshell#36>", line 2, in SearchWayne
    driver = webdriver.PhantomJS()
  File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 50, in __init__
    self.service.start()
  File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 69, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen


no dice.
Last edited by Yoriz on Sun Apr 27, 2014 6:01 pm, edited 1 time in total.
Reason: Changed Title.
Poppins586
 
Posts: 1
Joined: Fri Apr 25, 2014 5:55 pm

Re: Website url does not change

Postby 7stud » Sat Apr 26, 2014 5:59 pm

I don't know about the various things you mentioned in your introduction, but let's examine this error:

Code: Select all
browser.find_by_name('Accept').click()

AttributeError: 'ElementList' object has no attribute 'click'


find_by_name().....well, in an html page many elements can have the same name, so it stands to reason that find_by_name() returns a list; and in fact a cursory search of the splinter api hints at the fact that find_by_name() returns a list:

Finds elements in current page...


And then there is that error message:

'ElementList' object ...


So it seems reasonable to conclude that a list of Elements does not have a click() method, but that maybe each Element in the list does have a click() method, i.e. you don't call click() on a list, you call click() on an item in the list.
7stud
 
Posts: 99
Joined: Wed Apr 02, 2014 2:36 am


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests