Skip to content

Commit 02a4d98

Browse files
Cong Liurogerwang
authored andcommitted
[test] use ActionChains send keys to element avoid webdriver issues
`driver.find_element_by_id().send_keys()` will cause an error of "cannot focus element". This happens for typing into inputs of console of DevTools, which is using CodeMirror. Use `ActionChains(driver).send_keys()` can workaround this issue. Fixed test cases: * issue3780-jailed * issue3835-inspect-crash
1 parent 2803deb commit 02a4d98

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

test/sanity/issue3780-jailed/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
print 'switch to devtools'
2424
switch_to_devtools(driver, devtools_window=driver.window_handles[-1])
2525
print 'click Console panel'
26-
driver.execute_script('return document.querySelector(".tabbed-pane").shadowRoot.getElementById("tab-console")').click()
26+
devtools_click_tab(driver, 'console')
2727
print 'send_keys "location.pathname<enter>"'
28-
driver.find_element_by_id('console-prompt').send_keys('location.pathname\n')
28+
devtools_type_in_console(driver, 'location.pathname\n')
2929
pathname = driver.find_element_by_css_selector('.console-user-command-result .console-message-text .object-value-string').get_attribute('textContent')
3030
print pathname
3131
assert (pathname == '/child.html')

test/sanity/issue3835-inspect-crash/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
print driver.window_handles
2121
print 'switch to devtools'
2222
switch_to_devtools(driver, devtools_window=driver.window_handles[-1])
23-
driver.execute_script('return document.querySelector(".tabbed-pane").shadowRoot.getElementById("tab-console")').click()
24-
driver.find_element_by_id('console-prompt').send_keys('chrome\n')
23+
print 'click Console panel'
24+
devtools_click_tab(driver, 'console')
25+
print 'send_keys "chrome<enter>"'
26+
devtools_type_in_console(driver, 'chrome\n')
2527
driver.find_element_by_class_name('console-object-preview').click()
2628
time.sleep(1) # wait for crash!
2729
expanded = driver.find_element_by_css_selector('.console-view-object-properties-section.expanded')

test/sanity/nw_util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import platform
33
import subprocess
44
import selenium
5+
from selenium.webdriver.common.action_chains import ActionChains
56

67
# wait for window handles
78
def wait_window_handles(driver, until, timeout=60):
@@ -41,6 +42,13 @@ def switch_to_devtools(driver, devtools_window=None):
4142
while driver.execute_script('return document.readyState') != 'complete':
4243
time.sleep(1)
4344

45+
def devtools_click_tab(driver, tab_name):
46+
driver.execute_script('return document.querySelector(".tabbed-pane").shadowRoot.getElementById("tab-%s")' % tab_name).click()
47+
48+
def devtools_type_in_console(driver, keys):
49+
console_prompt = driver.find_element_by_id('console-prompt')
50+
ActionChains(driver).click(console_prompt).send_keys(keys).perform()
51+
4452
def no_live_process(driver, print_if_fail=True):
4553
if platform.system() == 'Windows':
4654
pgrep = subprocess.Popen(['wmic', 'process', 'where', '(ParentProcessId=%s)' % driver.service.process.pid, 'get', 'ProcessId'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

0 commit comments

Comments
 (0)