Executive summary:
After creating a selenium webdriver object - either phantomjs or chrome - [info object methods $obj] doesn't include find_element_by_xpath.
Long story:
After a couple of years messing about with other ways to scrape web sites, I have finally got to grips with selenium-tcl. (I probably downloaded it from sourceforge as advertised on the wiki, at
wiki.tcl.tk/selenium, but I can't be quite sure.)
I have a cunning plan to wrap the selenium drivers in a class of my own to provide some extra bits and pieces, and have code something like
oo::class create myDriver {
variable m_driver
constructor {} {
set m_driver [selenium::webdrivers::phantomjs::PhantomJSdriver new]
foreach methName [info object methods $m_driver -all] {
oo::objdefine [self object] forward $methName $m_driver $methName
}
.
.
.
}
.
.
.
}
Sadly, however, when I subsequently to
set d [myDriver new]
$d get $someUrl
$d find_element_by_spath $someXPath
My script throws
unknown method "find_element_by_xpath": must be accept_alert, ...
But, selenium::webdrivers::phantomjs::PhantomJSdriver has selenium::WebDriver as a superclass, and selenium::WebDriver has a find_element_by_xpath method.
% info class superclasses selenium::webdrivers::phantomjs::PhantomJSdriver
::selenium::WebDriver
% info class methods selenium::webdrivers::phantomjs::PhantomJSdriver
stop_client start_client service_url
% info class methods selenium::webdrivers::phantomjs::PhantomJSdriver -all
accept_alert active_webelement add_cookie alert_text available_log_types back clear_text close create_container_of_webelements create_webelement css_property current_capabilities current_url current_window_handle delete_all_cookies delete_cookie destroy dismiss_alert execute execute_and_get_value execute_javascript execute_script forward freeze get get_app_cache_status get_attribute get_base64_image get_cookie get_cookies get_location get_log get_rect get_screen_orientation get_screenshot_as_base64 get_screenshot_as_file get_screenshot_as_png get_text get_visible_text get_window_position get_window_size implicitly_wait is_displayed is_enabled is_select_element is_selected location_once_scrolled_into_view maximize_window move_mouse_to name network_connection page_source quit refresh remove_webelement_from_DOM save_screenshot select_element send_keys send_keys_to_alert service_url session_ID set_network_connection set_page_load_timeout set_screen_orientation set_script_timeout set_window_position set_window_size size start_client start_session stop_client submit_form switch_to_default_frame switch_to_frame switch_to_parent_frame switch_to_window tag_name title typewrite wait_until_connectable wait_until_not_connectable window_handles
% info class methods selenium::WebDriver -all
accept_alert active_webelement add_cookie alert_text available_log_types back clear_text click click_and_hold close create_container_of_webelements create_webelement css_property current_capabilities current_url current_window_handle delete_all_cookies delete_cookie destroy dismiss_alert double_click execute execute_and_get_value execute_javascript execute_script find_element find_element_by_class_name find_element_by_css_selector find_element_by_id find_element_by_link_text find_element_by_name find_element_by_partial_link_text find_element_by_tag_name find_element_by_xpath find_elements find_elements_by_class_name find_elements_by_css_selector find_elements_by_id find_elements_by_link_text find_elements_by_name find_elements_by_partial_link_text find_elements_by_tag_name find_elements_by_xpath forward freeze get get_app_cache_status get_attribute get_base64_image get_cookie get_cookies get_location get_log get_rect get_screen_orientation get_screenshot_as_base64 get_screenshot_as_file get_screenshot_as_png get_text get_visible_text get_window_position get_window_size implicitly_wait is_displayed is_enabled is_select_element is_selected location_once_scrolled_into_view maximize_window mouse_down mouse_up move_mouse move_mouse_to move_mouse_to_element name network_connection page_source quit refresh remove_webelement_from_DOM save_screenshot scroll_into_view scroll_to_bottom scroll_to_bottom_infinitely scrolling_position select_element send_keys send_keys_to_alert session_ID set_network_connection set_page_load_timeout set_screen_orientation set_script_timeout set_window_position set_window_size size start_client start_session stop_client submit_form switch_to_default_frame switch_to_frame switch_to_parent_frame switch_to_window tag_name title typewrite wait_until_connectable wait_until_not_connectable window_handles
% info object class oo::Obj66
::selenium::webdrivers::phantomjs::PhantomJSdriver
% info object methods oo::Obj66 -all
accept_alert active_webelement add_cookie alert_text available_log_types back clear_text close create_container_of_webelements create_webelement css_property current_capabilities current_url current_window_handle delete_all_cookies delete_cookie destroy dismiss_alert execute execute_and_get_value execute_javascript execute_script forward freeze get get_app_cache_status get_attribute get_base64_image get_cookie get_cookies get_location get_log get_rect get_screen_orientation get_screenshot_as_base64 get_screenshot_as_file get_screenshot_as_png get_text get_visible_text get_window_position get_window_size implicitly_wait is_displayed is_enabled is_select_element is_selected location_once_scrolled_into_view maximize_window move_mouse_to name network_connection page_source quit refresh remove_webelement_from_DOM save_screenshot select_element send_keys send_keys_to_alert service_url session_ID set_network_connection set_page_load_timeout set_screen_orientation set_script_timeout set_window_position set_window_size size start_client start_session stop_client submit_form switch_to_default_frame switch_to_frame switch_to_parent_frame switch_to_window tag_name title typewrite wait_until_connectable wait_until_not_connectable window_handles
Sorry about the length of this post; the problem doesn't show up with the simple subclass/superclass setup I tried - I hope knowledgeable people may be able to identify what's going on here maybe with reference to the selenium-tcl sources. I'll happily try to construct a simpler example if pointed in the direction of ow to simplify. Similarly, any comments on whether I would do better to wrap the object differently are welcome.