|
21 | 21 |
|
22 | 22 | from autowebcompat import utils |
23 | 23 |
|
24 | | -already_clicked_elems = set() |
25 | | - |
26 | 24 | MAX_THREADS = 5 |
27 | 25 | MAX_INTERACTION_DEPTH = 7 |
28 | 26 |
|
@@ -135,6 +133,7 @@ def was_visited(current_path, visited_paths, elem_properties): |
135 | 133 |
|
136 | 134 |
|
137 | 135 | def do_something(driver, visited_paths, current_path, elem_properties=None, xpath=None): |
| 136 | + already_clicked_elems = set() |
138 | 137 | not_clickable_elems = set() |
139 | 138 | while True: |
140 | 139 | elem = None |
@@ -181,79 +180,85 @@ def do_something(driver, visited_paths, current_path, elem_properties=None, xpat |
181 | 180 | break |
182 | 181 | else: |
183 | 182 | children_to_ignore.extend(elems) |
184 | | - else: |
185 | | - if 'id' in elem_properties['attributes'].keys(): |
186 | | - elem_id = elem_properties['attributes']['id'] |
187 | | - elem = driver.find_element_by_id(elem_id) |
188 | | - if xpath is None: |
189 | | - xpath = driver.execute_script(get_xpath_script, elem) |
190 | | - elif xpath is not None: |
191 | | - try: |
192 | | - elem = driver.find_element_by_xpath(xpath) |
193 | | - except NoSuchElementException: |
194 | | - elems = get_elements_with_properties(driver, elem_properties, children) |
195 | | - assert len(elems) == 1 |
196 | | - elem = elems[0] |
197 | | - xpath = driver.execute_script(get_xpath_script, elem) |
198 | | - else: |
| 183 | + except (ElementNotInteractableException, StaleElementReferenceException, InvalidSelectorException, WebDriverException): |
| 184 | + # Ignore frequent exceptions. |
| 185 | + traceback.print_exc() |
| 186 | + not_clickable_elems.add(elem) |
| 187 | + close_all_windows_except_first(driver) |
| 188 | + else: |
| 189 | + try: |
| 190 | + if 'id' in elem_properties['attributes'].keys(): |
| 191 | + elem_id = elem_properties['attributes']['id'] |
| 192 | + elem = driver.find_element_by_id(elem_id) |
| 193 | + if xpath is None: |
| 194 | + xpath = driver.execute_script(get_xpath_script, elem) |
| 195 | + elif xpath is not None: |
| 196 | + try: |
| 197 | + elem = driver.find_element_by_xpath(xpath) |
| 198 | + except NoSuchElementException: |
199 | 199 | elems = get_elements_with_properties(driver, elem_properties, children) |
200 | 200 | assert len(elems) == 1 |
201 | 201 | elem = elems[0] |
202 | 202 | xpath = driver.execute_script(get_xpath_script, elem) |
203 | | - |
204 | | - if elem is None: |
205 | | - return None |
206 | | - |
207 | | - driver.execute_script('arguments[0].scrollIntoView();', elem) |
208 | | - |
209 | | - if elem.tag_name in ['button', 'a']: |
210 | | - elem.click() |
211 | | - elif elem.tag_name == 'input': |
212 | | - input_type = elem.get_attribute('type') |
213 | | - if input_type == 'url': |
214 | | - elem.send_keys('http://www.mozilla.org/') |
215 | | - elif input_type == 'text': |
216 | | - elem.send_keys('marco') |
217 | | - elif input_type == 'email': |
218 | | - elem. send_keys( '[email protected]') |
219 | | - elif input_type == 'password': |
220 | | - elem.send_keys('aMildlyComplexPasswordIn2017') |
221 | | - elif input_type == 'checkbox': |
222 | | - elem.click() |
223 | | - elif input_type == 'number': |
224 | | - elem.send_keys('3') |
225 | | - elif input_type == 'radio': |
226 | | - elem.click() |
227 | | - elif input_type == 'tel': |
228 | | - elem.send_keys('1234567890') |
229 | | - elif input_type == 'date': |
230 | | - elem.send_keys('20000101') |
231 | | - elif input_type == 'search': |
232 | | - elem.clear() |
233 | | - elem.send_keys('quick search') |
234 | | - elif input_type in ['submit', 'reset', 'button']: |
235 | | - elem.click() |
236 | | - elif input_type == 'color': |
237 | | - driver.execute_script("arguments[0].value = '#ff0000'", elem) |
238 | | - else: |
239 | | - raise Exception('Unsupported input type: %s' % input_type) |
240 | | - elif elem.tag_name == 'select': |
241 | | - for option in elem.find_elements_by_tag_name('option'): |
242 | | - if option.text != '': |
243 | | - option.click() |
244 | | - break |
245 | | - |
246 | | - already_clicked_elems.add(elem) |
247 | | - |
248 | | - close_all_windows_except_first(driver) |
249 | | - |
250 | | - return elem_properties, xpath |
251 | | - |
252 | | - except(ElementNotInteractableException, StaleElementReferenceException, InvalidSelectorException, WebDriverException): |
| 203 | + else: |
| 204 | + elems = get_elements_with_properties(driver, elem_properties, children) |
| 205 | + assert len(elems) == 1 |
| 206 | + elem = elems[0] |
| 207 | + xpath = driver.execute_script(get_xpath_script, elem) |
| 208 | + except (ElementNotInteractableException, StaleElementReferenceException, InvalidSelectorException, WebDriverException): |
| 209 | + # Ignore frequent exceptions. |
253 | 210 | traceback.print_exc() |
254 | 211 | not_clickable_elems.add(elem) |
255 | 212 | close_all_windows_except_first(driver) |
256 | 213 |
|
| 214 | + if elem is None: |
| 215 | + return None |
| 216 | + |
| 217 | + driver.execute_script('arguments[0].scrollIntoView();', elem) |
| 218 | + |
| 219 | + if elem.tag_name in ['button', 'a']: |
| 220 | + elem.click() |
| 221 | + elif elem.tag_name == 'input': |
| 222 | + input_type = elem.get_attribute('type') |
| 223 | + if input_type == 'url': |
| 224 | + elem.send_keys('http://www.mozilla.org/') |
| 225 | + elif input_type == 'text': |
| 226 | + elem.send_keys('marco') |
| 227 | + elif input_type == 'email': |
| 228 | + elem. send_keys( '[email protected]') |
| 229 | + elif input_type == 'password': |
| 230 | + elem.send_keys('aMildlyComplexPasswordIn2017') |
| 231 | + elif input_type == 'checkbox': |
| 232 | + elem.click() |
| 233 | + elif input_type == 'number': |
| 234 | + elem.send_keys('3') |
| 235 | + elif input_type == 'radio': |
| 236 | + elem.click() |
| 237 | + elif input_type == 'tel': |
| 238 | + elem.send_keys('1234567890') |
| 239 | + elif input_type == 'date': |
| 240 | + elem.send_keys('20000101') |
| 241 | + elif input_type == 'search': |
| 242 | + elem.clear() |
| 243 | + elem.send_keys('quick search') |
| 244 | + elif input_type in ['submit', 'reset', 'button']: |
| 245 | + elem.click() |
| 246 | + elif input_type == 'color': |
| 247 | + driver.execute_script("arguments[0].value = '#ff0000'", elem) |
| 248 | + else: |
| 249 | + raise Exception('Unsupported input type: %s' % input_type) |
| 250 | + elif elem.tag_name == 'select': |
| 251 | + for option in elem.find_elements_by_tag_name('option'): |
| 252 | + if option.text != '': |
| 253 | + option.click() |
| 254 | + break |
| 255 | + |
| 256 | + already_clicked_elems.add(elem) |
| 257 | + |
| 258 | + close_all_windows_except_first(driver) |
| 259 | + |
| 260 | + return elem_properties, xpath |
| 261 | + |
257 | 262 |
|
258 | 263 | def screenshot(driver, bug_id, browser, seq_no): |
259 | 264 | WINDOW_HEIGHT = 732 |
@@ -443,7 +448,6 @@ def run_tests(firefox_driver, chrome_driver, bugs): |
443 | 448 | def main(bugs): |
444 | 449 | firefox_driver = webdriver.Firefox(firefox_profile=firefox_profile, firefox_binary=nightly_bin) |
445 | 450 | chrome_driver = webdriver.Chrome(chrome_options=chrome_options) |
446 | | - already_clicked_elems.clear() |
447 | 451 | run_tests(firefox_driver, chrome_driver, bugs) |
448 | 452 |
|
449 | 453 |
|
|
0 commit comments