Last active
September 28, 2015 02:18
-
-
Save pobing/1369094 to your computer and use it in GitHub Desktop.
Capybara 获取元素 支持JS &jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scripting | |
一、In drivers which support it, you can easily execute JavaScript: | |
page.execute_script("$('body').empty()") | |
For simple expressions, you can return the result of the script. Note that this may break with more complicated expressions: | |
result = page.evaluate_script('4 + 4'); | |
二、 page.execute_script("$('div:eq(0)').length") | |
page.execute_script("document.getElementById('wrapper')") | |
page.execute_script("document.getElementsByTagName('body')"); | |
page.execute_script %Q{ $('li').eq(1).trigger("mouseenter").click(); } | |
三、selenium+capybara 获取svg tag 里的元素 | |
eg1: page.execute_script("$('svg image:first').click();") | |
eg2: $('svg image:first').get(0)); | |
eg3:page.execute_script("$('#editTableDialog_priv_tab_0').find('span:eq(1) .privName').trigger('click').find(':text').val('考勤权限');") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment