{"action":"created","comment":{"url":"https://api.github.com/repos/scrapinghub/splash/pulls/comments/73953626","id":73953626,"diff_hunk":"@@ -3925,3 +3925,433 @@ def test_key_error(self):\n         \"\"\")\n         self.assertScriptError(resp, ScriptError.SPLASH_LUA_ERROR,\n                                message=\"Unknown key\")\n+\n+\n+class HTMLElementTest(BaseLuaRenderTest):\n+    def test_select(self):\n+        resp = self.request_lua(\"\"\"\n+        function main(splash)\n+            assert(splash:go(splash.args.url))\n+            assert(splash:wait(0.1))\n+\n+            local p = splash:select('p')\n+            local form = splash:select('form#login')\n+            local username = splash:select('input[name=\"username\"]')\n+            local password = splash:select('input[name=\"password\"]')\n+            local title = splash:select('.title')\n+\n+            return {\n+                p=select(2, assert(p:node_property('nodeName'))):lower(),\n+                form=select(2, assert(form:node_property('nodeName'))):lower(),\n+                username=select(2, assert(username:node_property('nodeName'))):lower(),\n+                password=select(2, assert(password:node_property('nodeName'))):lower(),\n+                title=select(2, assert(title:node_property('nodeName'))):lower(),\n+            }\n+        end\n+        \"\"\", {\"url\": self.mockurl(\"various-elements\")})\n+\n+        self.assertStatusCode(resp, 200)\n+        self.assertEqual(resp.json(), {\n+            \"p\": \"p\",\n+            \"form\": \"form\",\n+            \"username\": \"input\",\n+            \"password\": \"input\",\n+            \"title\": \"h1\"\n+        })\n+\n+    def test_element_ids(self):\n+        resp = self.request_lua(\"\"\"\n+        local treat = require('treat')\n+        function main(splash)\n+            assert(splash:go(splash.args.url))\n+            assert(splash:wait(0.1))\n+\n+            local p = splash:select('p')\n+            local form = splash:select('form#login')\n+            local username = splash:select('input[name=\"username\"]')\n+            local password = splash:select('input[name=\"password\"]')\n+            local title = splash:select('.title')\n+\n+            return treat.as_array({\n+                p.id,\n+                form.id,\n+                username.id,\n+                password.id,\n+                title.id,\n+            })\n+        end\n+        \"\"\", {\"url\": self.mockurl(\"various-elements\")})\n+\n+        self.assertStatusCode(resp, 200)\n+        ids = resp.json()\n+        self.assertEqual(len(ids) == (len(set(ids))), True)\n+\n+    def test_bad_selector(self):\n+        resp = self.request_lua(\"\"\"\n+         function main(splash)\n+            assert(splash:go(splash.args.url))\n+            assert(splash:wait(0.1))\n+\n+            local element = splash:select('!notaselector')\n+\n+            return element:exists()\n+        end\n+        \"\"\", {\"url\": self.mockurl(\"various-elements\")})\n+\n+        self.assertStatusCode(resp, 400)\n+        err = self.assertScriptError(resp, ScriptError.SPLASH_LUA_ERROR)\n+        self.assertEqual(err[\"info\"][\"splash_method\"], \"select\")\n+\n+    def test_node_property_returns_element(self):\n+        resp = self.request_lua(\"\"\"\n+        function main(splash)\n+            assert(splash:go(splash.args.url))\n+            assert(splash:wait(0.1))\n+\n+            local p = splash:select('p')\n+            local ok, parent = p:node_property('parentNode')\n+            local ok, remove = parent:node_method('remove')","path":"splash/tests/test_execute.py","position":107,"original_position":107,"commit_id":"8ea320b41ba39ac75344c8195a6308bf2d55f3ba","original_commit_id":"8ea320b41ba39ac75344c8195a6308bf2d55f3ba","user":{"login":"kmike","id":107893,"avatar_url":"https://avatars.githubusercontent.com/u/107893?v=3","gravatar_id":"","url":"https://api.github.com/users/kmike","html_url":"https://github.com/kmike","followers_url":"https://api.github.com/users/kmike/followers","following_url":"https://api.github.com/users/kmike/following{/other_user}","gists_url":"https://api.github.com/users/kmike/gists{/gist_id}","starred_url":"https://api.github.com/users/kmike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmike/subscriptions","organizations_url":"https://api.github.com/users/kmike/orgs","repos_url":"https://api.github.com/users/kmike/repos","events_url":"https://api.github.com/users/kmike/events{/privacy}","received_events_url":"https://api.github.com/users/kmike/received_events","type":"User","site_admin":false},"body":"`splash:select('p'):node_property('parentNone'):node_method('remove')()` is so much nicer when you're writing quick scraping scripts :) I woder if we should sacrifice `ok, result` consistency and start returning nil objects or raising errors","created_at":"2016-08-08T21:00:37Z","updated_at":"2016-08-08T21:00:37Z","html_url":"https://github.com/scrapinghub/splash/pull/471#discussion_r73953626","pull_request_url":"https://api.github.com/repos/scrapinghub/splash/pulls/471","_links":{"self":{"href":"https://api.github.com/repos/scrapinghub/splash/pulls/comments/73953626"},"html":{"href":"https://github.com/scrapinghub/splash/pull/471#discussion_r73953626"},"pull_request":{"href":"https://api.github.com/repos/scrapinghub/splash/pulls/471"}}},"pull_request":{"url":"https://api.github.com/repos/scrapinghub/splash/pulls/471","id":74829169,"html_url":"https://github.com/scrapinghub/splash/pull/471","diff_url":"https://github.com/scrapinghub/splash/pull/471.diff","patch_url":"https://github.com/scrapinghub/splash/pull/471.patch","issue_url":"https://api.github.com/repos/scrapinghub/splash/issues/471","number":471,"state":"open","locked":false,"title":"[WIP] Add Element class for manipulating DOM elements in Lua","user":{"login":"mike1808","id":3942554,"avatar_url":"https://avatars.githubusercontent.com/u/3942554?v=3","gravatar_id":"","url":"https://api.github.com/users/mike1808","html_url":"https://github.com/mike1808","followers_url":"https://api.github.com/users/mike1808/followers","following_url":"https://api.github.com/users/mike1808/following{/other_user}","gists_url":"https://api.github.com/users/mike1808/gists{/gist_id}","starred_url":"https://api.github.com/users/mike1808/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike1808/subscriptions","organizations_url":"https://api.github.com/users/mike1808/orgs","repos_url":"https://api.github.com/users/mike1808/repos","events_url":"https://api.github.com/users/mike1808/events{/privacy}","received_events_url":"https://api.github.com/users/mike1808/received_events","type":"User","site_admin":false},"body":"some test lua code\r\n\r\n```lua\r\nfunction main(splash)\r\n  assert(splash:go('http://localhost:8000/'))\r\n\r\n  local element = splash:select('button')\r\n  element:mouse_click()\r\n  assert(splash:wait(0.0001))\r\n\r\n  local title = splash:select('#title')\r\n\r\n  return {title:get_styles()[\"display\"], title:node_property('nodeName')}\r\nend\r\n```\r\nfor the following html\r\n```html\r\n<!DOCTYPE html>\r\n<html>\r\n<head>\r\n   <title>Index 1</title>\r\n</head>\r\n<body>\r\n<button type=\"button\" onclick=\"document.getElementById('title').style.display = 'block'\">Click me</button>\r\n<h1 id=\"title\" style=\"display: none\">Index 1</h1>\r\n</body>\r\n</html>\r\n```","created_at":"2016-06-22T17:59:44Z","updated_at":"2016-08-08T21:00:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe94f80acfde5f49d2795ec649bfdaf5ca97fdd0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scrapinghub/splash/pulls/471/commits","review_comments_url":"https://api.github.com/repos/scrapinghub/splash/pulls/471/comments","review_comment_url":"https://api.github.com/repos/scrapinghub/splash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scrapinghub/splash/issues/471/comments","statuses_url":"https://api.github.com/repos/scrapinghub/splash/statuses/8ea320b41ba39ac75344c8195a6308bf2d55f3ba","head":{"label":"mike1808:dom-element","ref":"dom-element","sha":"8ea320b41ba39ac75344c8195a6308bf2d55f3ba","user":{"login":"mike1808","id":3942554,"avatar_url":"https://avatars.githubusercontent.com/u/3942554?v=3","gravatar_id":"","url":"https://api.github.com/users/mike1808","html_url":"https://github.com/mike1808","followers_url":"https://api.github.com/users/mike1808/followers","following_url":"https://api.github.com/users/mike1808/following{/other_user}","gists_url":"https://api.github.com/users/mike1808/gists{/gist_id}","starred_url":"https://api.github.com/users/mike1808/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike1808/subscriptions","organizations_url":"https://api.github.com/users/mike1808/orgs","repos_url":"https://api.github.com/users/mike1808/repos","events_url":"https://api.github.com/users/mike1808/events{/privacy}","received_events_url":"https://api.github.com/users/mike1808/received_events","type":"User","site_admin":false},"repo":{"id":54326662,"name":"splash","full_name":"mike1808/splash","owner":{"login":"mike1808","id":3942554,"avatar_url":"https://avatars.githubusercontent.com/u/3942554?v=3","gravatar_id":"","url":"https://api.github.com/users/mike1808","html_url":"https://github.com/mike1808","followers_url":"https://api.github.com/users/mike1808/followers","following_url":"https://api.github.com/users/mike1808/following{/other_user}","gists_url":"https://api.github.com/users/mike1808/gists{/gist_id}","starred_url":"https://api.github.com/users/mike1808/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike1808/subscriptions","organizations_url":"https://api.github.com/users/mike1808/orgs","repos_url":"https://api.github.com/users/mike1808/repos","events_url":"https://api.github.com/users/mike1808/events{/privacy}","received_events_url":"https://api.github.com/users/mike1808/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mike1808/splash","description":"Lightweight, scriptable browser as a service with an HTTP API","fork":true,"url":"https://api.github.com/repos/mike1808/splash","forks_url":"https://api.github.com/repos/mike1808/splash/forks","keys_url":"https://api.github.com/repos/mike1808/splash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mike1808/splash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mike1808/splash/teams","hooks_url":"https://api.github.com/repos/mike1808/splash/hooks","issue_events_url":"https://api.github.com/repos/mike1808/splash/issues/events{/number}","events_url":"https://api.github.com/repos/mike1808/splash/events","assignees_url":"https://api.github.com/repos/mike1808/splash/assignees{/user}","branches_url":"https://api.github.com/repos/mike1808/splash/branches{/branch}","tags_url":"https://api.github.com/repos/mike1808/splash/tags","blobs_url":"https://api.github.com/repos/mike1808/splash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mike1808/splash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mike1808/splash/git/refs{/sha}","trees_url":"https://api.github.com/repos/mike1808/splash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mike1808/splash/statuses/{sha}","languages_url":"https://api.github.com/repos/mike1808/splash/languages","stargazers_url":"https://api.github.com/repos/mike1808/splash/stargazers","contributors_url":"https://api.github.com/repos/mike1808/splash/contributors","subscribers_url":"https://api.github.com/repos/mike1808/splash/subscribers","subscription_url":"https://api.github.com/repos/mike1808/splash/subscription","commits_url":"https://api.github.com/repos/mike1808/splash/commits{/sha}","git_commits_url":"https://api.github.com/repos/mike1808/splash/git/commits{/sha}","comments_url":"https://api.github.com/repos/mike1808/splash/comments{/number}","issue_comment_url":"https://api.github.com/repos/mike1808/splash/issues/comments{/number}","contents_url":"https://api.github.com/repos/mike1808/splash/contents/{+path}","compare_url":"https://api.github.com/repos/mike1808/splash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mike1808/splash/merges","archive_url":"https://api.github.com/repos/mike1808/splash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mike1808/splash/downloads","issues_url":"https://api.github.com/repos/mike1808/splash/issues{/number}","pulls_url":"https://api.github.com/repos/mike1808/splash/pulls{/number}","milestones_url":"https://api.github.com/repos/mike1808/splash/milestones{/number}","notifications_url":"https://api.github.com/repos/mike1808/splash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mike1808/splash/labels{/name}","releases_url":"https://api.github.com/repos/mike1808/splash/releases{/id}","deployments_url":"https://api.github.com/repos/mike1808/splash/deployments","created_at":"2016-03-20T16:00:44Z","updated_at":"2016-03-20T16:00:45Z","pushed_at":"2016-08-07T13:41:43Z","git_url":"git://github.com/mike1808/splash.git","ssh_url":"git@github.com:mike1808/splash.git","clone_url":"https://github.com/mike1808/splash.git","svn_url":"https://github.com/mike1808/splash","homepage":"","size":2729,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scrapinghub:master","ref":"master","sha":"fa2f50e6b1a4a6fe153b475b1a99519374b6d06c","user":{"login":"scrapinghub","id":699596,"avatar_url":"https://avatars.githubusercontent.com/u/699596?v=3","gravatar_id":"","url":"https://api.github.com/users/scrapinghub","html_url":"https://github.com/scrapinghub","followers_url":"https://api.github.com/users/scrapinghub/followers","following_url":"https://api.github.com/users/scrapinghub/following{/other_user}","gists_url":"https://api.github.com/users/scrapinghub/gists{/gist_id}","starred_url":"https://api.github.com/users/scrapinghub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrapinghub/subscriptions","organizations_url":"https://api.github.com/users/scrapinghub/orgs","repos_url":"https://api.github.com/users/scrapinghub/repos","events_url":"https://api.github.com/users/scrapinghub/events{/privacy}","received_events_url":"https://api.github.com/users/scrapinghub/received_events","type":"Organization","site_admin":false},"repo":{"id":10182205,"name":"splash","full_name":"scrapinghub/splash","owner":{"login":"scrapinghub","id":699596,"avatar_url":"https://avatars.githubusercontent.com/u/699596?v=3","gravatar_id":"","url":"https://api.github.com/users/scrapinghub","html_url":"https://github.com/scrapinghub","followers_url":"https://api.github.com/users/scrapinghub/followers","following_url":"https://api.github.com/users/scrapinghub/following{/other_user}","gists_url":"https://api.github.com/users/scrapinghub/gists{/gist_id}","starred_url":"https://api.github.com/users/scrapinghub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrapinghub/subscriptions","organizations_url":"https://api.github.com/users/scrapinghub/orgs","repos_url":"https://api.github.com/users/scrapinghub/repos","events_url":"https://api.github.com/users/scrapinghub/events{/privacy}","received_events_url":"https://api.github.com/users/scrapinghub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scrapinghub/splash","description":"Lightweight, scriptable browser as a service with an HTTP API","fork":false,"url":"https://api.github.com/repos/scrapinghub/splash","forks_url":"https://api.github.com/repos/scrapinghub/splash/forks","keys_url":"https://api.github.com/repos/scrapinghub/splash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scrapinghub/splash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scrapinghub/splash/teams","hooks_url":"https://api.github.com/repos/scrapinghub/splash/hooks","issue_events_url":"https://api.github.com/repos/scrapinghub/splash/issues/events{/number}","events_url":"https://api.github.com/repos/scrapinghub/splash/events","assignees_url":"https://api.github.com/repos/scrapinghub/splash/assignees{/user}","branches_url":"https://api.github.com/repos/scrapinghub/splash/branches{/branch}","tags_url":"https://api.github.com/repos/scrapinghub/splash/tags","blobs_url":"https://api.github.com/repos/scrapinghub/splash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scrapinghub/splash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scrapinghub/splash/git/refs{/sha}","trees_url":"https://api.github.com/repos/scrapinghub/splash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scrapinghub/splash/statuses/{sha}","languages_url":"https://api.github.com/repos/scrapinghub/splash/languages","stargazers_url":"https://api.github.com/repos/scrapinghub/splash/stargazers","contributors_url":"https://api.github.com/repos/scrapinghub/splash/contributors","subscribers_url":"https://api.github.com/repos/scrapinghub/splash/subscribers","subscription_url":"https://api.github.com/repos/scrapinghub/splash/subscription","commits_url":"https://api.github.com/repos/scrapinghub/splash/commits{/sha}","git_commits_url":"https://api.github.com/repos/scrapinghub/splash/git/commits{/sha}","comments_url":"https://api.github.com/repos/scrapinghub/splash/comments{/number}","issue_comment_url":"https://api.github.com/repos/scrapinghub/splash/issues/comments{/number}","contents_url":"https://api.github.com/repos/scrapinghub/splash/contents/{+path}","compare_url":"https://api.github.com/repos/scrapinghub/splash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scrapinghub/splash/merges","archive_url":"https://api.github.com/repos/scrapinghub/splash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scrapinghub/splash/downloads","issues_url":"https://api.github.com/repos/scrapinghub/splash/issues{/number}","pulls_url":"https://api.github.com/repos/scrapinghub/splash/pulls{/number}","milestones_url":"https://api.github.com/repos/scrapinghub/splash/milestones{/number}","notifications_url":"https://api.github.com/repos/scrapinghub/splash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scrapinghub/splash/labels{/name}","releases_url":"https://api.github.com/repos/scrapinghub/splash/releases{/id}","deployments_url":"https://api.github.com/repos/scrapinghub/splash/deployments","created_at":"2013-05-20T21:20:33Z","updated_at":"2016-08-07T13:18:37Z","pushed_at":"2016-08-08T19:41:03Z","git_url":"git://github.com/scrapinghub/splash.git","ssh_url":"git@github.com:scrapinghub/splash.git","clone_url":"https://github.com/scrapinghub/splash.git","svn_url":"https://github.com/scrapinghub/splash","homepage":"","size":3675,"stargazers_count":811,"watchers_count":811,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":144,"mirror_url":null,"open_issues_count":106,"forks":144,"open_issues":106,"watchers":811,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scrapinghub/splash/pulls/471"},"html":{"href":"https://github.com/scrapinghub/splash/pull/471"},"issue":{"href":"https://api.github.com/repos/scrapinghub/splash/issues/471"},"comments":{"href":"https://api.github.com/repos/scrapinghub/splash/issues/471/comments"},"review_comments":{"href":"https://api.github.com/repos/scrapinghub/splash/pulls/471/comments"},"review_comment":{"href":"https://api.github.com/repos/scrapinghub/splash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scrapinghub/splash/pulls/471/commits"},"statuses":{"href":"https://api.github.com/repos/scrapinghub/splash/statuses/8ea320b41ba39ac75344c8195a6308bf2d55f3ba"}}}}
{"actor":{"display_login":"kmike"}}