New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] splash:select, DOM elements manipulating helpers #490

Merged
merged 54 commits into from Nov 30, 2016

Conversation

Projects
None yet
4 participants
@mike1808
Contributor

mike1808 commented Aug 2, 2016

No description provided.

@mike1808 mike1808 changed the title from Elements event handlers to [WIP] Elements event handlers Aug 2, 2016

Show outdated Hide outdated splash/qtrender_lua.py
Show outdated Hide outdated splash/qtrender_lua.py
@mike1808

This comment has been minimized.

Show comment
Hide comment
@mike1808

mike1808 Aug 13, 2016

Contributor

I've added element:fill(values) method which set the values of the form using the provided values table. However, in comparison with casperjs it doesn't automatically submit the form and only supports the name selector type (the keys of the table are used to create the following selectors [name="<key>"]).

Contributor

mike1808 commented Aug 13, 2016

I've added element:fill(values) method which set the values of the form using the provided values table. However, in comparison with casperjs it doesn't automatically submit the form and only supports the name selector type (the keys of the table are used to create the following selectors [name="<key>"]).

@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Aug 15, 2016

Current coverage is 87.11% (diff: 95.62%)

Merging #490 into master will increase coverage by 0.51%

@@             master       #490   diff @@
==========================================
  Files            40         42     +2   
  Lines          4978       5495   +517   
  Methods           0          0          
  Messages          0          0          
  Branches        690        750    +60   
==========================================
+ Hits           4311       4787   +476   
- Misses          507        538    +31   
- Partials        160        170    +10   

Powered by Codecov. Last update 3caa40f...db4b7db

codecov-io commented Aug 15, 2016

Current coverage is 87.11% (diff: 95.62%)

Merging #490 into master will increase coverage by 0.51%

@@             master       #490   diff @@
==========================================
  Files            40         42     +2   
  Lines          4978       5495   +517   
  Methods           0          0          
  Messages          0          0          
  Branches        690        750    +60   
==========================================
+ Hits           4311       4787   +476   
- Misses          507        538    +31   
- Partials        160        170    +10   

Powered by Codecov. Last update 3caa40f...db4b7db

@mike1808 mike1808 changed the title from [WIP] Elements event handlers to [WIP] splash:select, DOM elements manipulating helpers Aug 15, 2016

def send_keys(self, text):
""" Send key events to the element separated by whitespaces """
self.mouse_click()
self.tab.send_keys(text)

This comment has been minimized.

@immerrr

immerrr Aug 15, 2016

Contributor

Why do we do mouse_click and not focus here? (asking as a person who rarely uses his mouse and prefers to TAB-TAB-TAB around form fields)

@immerrr

immerrr Aug 15, 2016

Contributor

Why do we do mouse_click and not focus here? (asking as a person who rarely uses his mouse and prefers to TAB-TAB-TAB around form fields)

This comment has been minimized.

@mike1808

mike1808 Aug 15, 2016

Contributor

What is the significant difference between clicking on an input and triggering focus event?

@mike1808

mike1808 Aug 15, 2016

Contributor

What is the significant difference between clicking on an input and triggering focus event?

This comment has been minimized.

@immerrr

immerrr Aug 15, 2016

Contributor

In a normal scenario, not much, clicking an input element should "focus" it.

But it might do strange things when you're trying to send_keys to clickable elements like buttons and links or when mouse-related event handlers define different behaviour.

@immerrr

immerrr Aug 15, 2016

Contributor

In a normal scenario, not much, clicking an input element should "focus" it.

But it might do strange things when you're trying to send_keys to clickable elements like buttons and links or when mouse-related event handlers define different behaviour.

This comment has been minimized.

@mike1808

mike1808 Aug 16, 2016

Contributor

I remembered why I used mouse_click here. I've tried to use focus using self.node_method('focus') and it wasn't working. Because when you call node_method it evaluates JS which is not immediate operation. On the contrary, calling mouse_click generates mouse click event using Qt.

@mike1808

mike1808 Aug 16, 2016

Contributor

I remembered why I used mouse_click here. I've tried to use focus using self.node_method('focus') and it wasn't working. Because when you call node_method it evaluates JS which is not immediate operation. On the contrary, calling mouse_click generates mouse click event using Qt.

* keys - string representing the keys to be sent as keyboard events.
**Returns:** ``ok, reason`` pair. If ``ok`` is nil then error happened during the

This comment has been minimized.

@kmike

kmike Aug 22, 2016

Member

in signature it is just 'ok'

@kmike

kmike Aug 22, 2016

Member

in signature it is just 'ok'

* text - string to be sent as input.
**Returns:** ``ok, reason`` pair. If ``ok`` is nil then error happened during the

This comment has been minimized.

@kmike

kmike Aug 22, 2016

Member

(fixed) in signature it is just 'ok', not 'ok, reason' pair

@kmike

kmike Aug 22, 2016

Member

(fixed) in signature it is just 'ok', not 'ok, reason' pair

Using :ref:`splash-select` you can get the element that matches your specified CSS selector like using
`document.querySelector`_ in your browser. The returned element is a :ref:`splash-element` which has many useful
methods and almost all methods and attributes that element has in JavaScript.

This comment has been minimized.

@kmike

kmike Aug 22, 2016

Member

What happens when an element can't be found - is this correct that nil is returned? I think it should be documented. Returning nil also means el = assert(splash:select("")) can be used.

@kmike

kmike Aug 22, 2016

Member

What happens when an element can't be found - is this correct that nil is returned? I think it should be documented. Returning nil also means el = assert(splash:select("")) can be used.

This comment has been minimized.

@mike1808

mike1808 Aug 22, 2016

Contributor

Updated docs.

@mike1808

mike1808 Aug 22, 2016

Contributor

Updated docs.

Show outdated Hide outdated docs/scripting-ref.rst
return Array.prototype.slice.call(o).map(storeNode);
}
return o;

This comment has been minimized.

@kmike

kmike Aug 22, 2016

Member

Does it mean user can return {type: 'node', id: '...'} and Splash will think a DOM element was returned? What do you think about always wrapping the result here - for non-node objects it can return e.g. {type: 'any', value: ...}, and for node lists it can return {type: 'nodelist', 'value': ...}, and the unwrapping the result?

@kmike

kmike Aug 22, 2016

Member

Does it mean user can return {type: 'node', id: '...'} and Splash will think a DOM element was returned? What do you think about always wrapping the result here - for non-node objects it can return e.g. {type: 'any', value: ...}, and for node lists it can return {type: 'nodelist', 'value': ...}, and the unwrapping the result?

Show outdated Hide outdated splash/browser_tab.py

mike1808 added some commits Aug 22, 2016

Show outdated Hide outdated splash/browser_tab.py
Show outdated Hide outdated splash/browser_tab.py
Show outdated Hide outdated splash/browser_tab.py
Show outdated Hide outdated splash/html_element.py
Show outdated Hide outdated splash/qtrender_lua.py
Show outdated Hide outdated splash/qtrender_lua.py
Show outdated Hide outdated splash/browser_tab.py
@kmike

This comment has been minimized.

Show comment
Hide comment
@kmike

kmike Aug 25, 2016

Member

It looks like the only item in TODO for this PR is to change the way DOM objects are passed from JS for Lua/Python, to fix issues like https://github.com/scrapinghub/splash/pull/490/files#r75652620 - result_protection=False shouldn't be used in most cases. Is there anything else left @mike1808 @immerrr?

Member

kmike commented Aug 25, 2016

It looks like the only item in TODO for this PR is to change the way DOM objects are passed from JS for Lua/Python, to fix issues like https://github.com/scrapinghub/splash/pull/490/files#r75652620 - result_protection=False shouldn't be used in most cases. Is there anything else left @mike1808 @immerrr?

@mike1808

This comment has been minimized.

Show comment
Hide comment
@mike1808

mike1808 Aug 25, 2016

Contributor

Also, I should make it work:

element.onclick = function(event)
    id =  event.target.node.id
end
Contributor

mike1808 commented Aug 25, 2016

Also, I should make it work:

element.onclick = function(event)
    id =  event.target.node.id
end

@kmike kmike referenced this pull request Nov 28, 2016

Merged

Gsoc2016 #531

6 of 6 tasks complete

@kmike kmike merged commit db4b7db into scrapinghub:master Nov 30, 2016

2 checks passed

codecov/patch 95.62% of diff hit (target 90.00%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@kmike

This comment has been minimized.

Show comment
Hide comment
@kmike

kmike Nov 30, 2016

Member

Merged in #531. Thanks @mike1808 for your work on this!

Member

kmike commented Nov 30, 2016

Merged in #531. Thanks @mike1808 for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment