How to use set_default_timeout method in SeleniumBase

Best Python code snippet using SeleniumBase

_interaction.py

Source:_interaction.py Github

copy

Full Screen

...39 只需要在特殊情况下使用此选项,例如导航到无法访问的页面。40 默认为 false。41 :param position: 相对于元素填充框的左上角使用的点。 如果未指定,则使用元素的一些可见点。42 :param timeout: 以毫秒为单位的最长时间,默认为 30 秒,传递 0 以禁用超时。可以使用43 browser_context.set_default_timeout(timeout)44 或 page.set_default_timeout(timeout) 方法更改默认值。45 """46 element = self._find_element_cross_frame(selector)47 element.check(48 force=force,49 no_wait_after=no_wait_after,50 position=position,51 timeout=timeout52 )53 def click(54 self,55 selector: str,56 *,57 button: Literal["left", "middle", "right"] = None,58 click_count: int = None,59 delay: float = None,60 force: bool = None,61 modifiers: Optional[62 List[Literal["Alt", "Control", "Meta", "Shift"]]63 ] = None,64 no_wait_after: bool = None,65 position: Position = None,66 timeout: float = None,67 ) -> NoneType:68 """此方法单击匹配选择器的元素。69 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。70 :param button: 鼠标的左、中(滚轮)、右按键。默认为左。71 :param click_count: 默认为 1。72 :param delay: 在 mousedown 和 mouseup 之间等待的时间(以毫秒为单位)。 默认为 0。73 :param force: 是否绕过可操作性检查。 默认为 false。74 :param modifiers: 要按下的修饰键。 确保在操作期间仅按下这些修饰符,然后将当前修饰符恢复回来。 如果未指定,则使用当前按下的修饰符。75 :param no_wait_after: 启动导航的操作正在等待这些导航发生并等待页面开始加载。 你可以通过设置此标志选择退出等待。76 只需要在特殊情况下使用此选项,例如导航到无法访问的页面。 默认为 false。77 :param position: 相对于元素填充框的左上角使用的点。 如果未指定,则使用元素的一些可见点。78 x <float>79 y <float>80 :param timeout: 以毫秒为单位的最长时间,默认为 30 秒,传递 0 以禁用超时。81 可以使用 browser_context.set_default_timeout(timeout) 或 page.set_default_timeout(timeout) 方法更改默认值。82 """83 element = self._find_element_cross_frame(selector)84 element.click(85 button=button,86 click_count=click_count,87 delay=delay,88 force=force,89 modifiers=modifiers,90 no_wait_after=no_wait_after,91 position=position,92 timeout=timeout93 )94 def cell_inner_text(self, *, row_header: str = None, column_headers: List[str] = None):95 """根据列标题 `column_headers` 和行标题 `row_header` 获得文本值。96 仅提供行标题 `row_header` 时,将获得其右侧最近的一个字段的文本值。97 :param column_headers: 列标题98 :param row_header: 行标题99 """100 return self.get_table_cell(row_header=row_header, column_headers=column_headers).inner_text()101 def cell_input_value(self, *, row_header: str = None, column_headers: List[str] = None):102 """根据列标题 `column_headers` 和行标题 `row_header` 获得 <input> 或 <textarea> 或 <select> 的 `value` 属性值。103 仅提供行标题 `row_header` 时,将获得其右侧最近的一个输入字段的 `value` 属性值。104 对于非输入元素抛出异常。105 :param column_headers: 列标题106 :param row_header: 行标题107 """108 _el = self.get_table_cell(row_header=row_header, column_headers=column_headers)109 tag_name = str(_el.get_property("tagName")).lower()110 if tag_name not in ["input", "textarea", "select"]:111 raise Error(112 "cell_input_value 仅作用于 <input>|<textarea>|<select> 元素,"113 f"不支持 <{tag_name}>。")114 return _el.get_attribute("value")115 def dblclick(116 self,117 selector: str,118 *,119 modifiers: Optional[120 List[Literal["Alt", "Control", "Meta", "Shift"]]121 ] = None,122 position: Position = None,123 delay: float = None,124 button: Literal["left", "middle", "right"] = None,125 timeout: float = None,126 force: bool = None,127 no_wait_after: bool = None,128 ) -> NoneType:129 """双击匹配选择器的元素。130 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。131 :param button: 鼠标的左、中(滚轮)、右按键。默认为左。132 :param delay: 在 mousedown 和 mouseup 之间等待的时间(以毫秒为单位)。 默认为 0。133 :param force: 是否绕过可操作性检查。 默认为 false。134 :param modifiers: 要按下的修饰键。 确保在操作期间仅按下这些修饰符,然后将当前修饰符恢复回来。 如果未指定,则使用当前按下的修饰符。135 :param no_wait_after: 启动导航的操作正在等待这些导航发生并等待页面开始加载。 你可以通过设置此标志选择退出等待。136 只需要在特殊情况下使用此选项,例如导航到无法访问的页面。 默认为 false。137 :param position: 相对于元素填充框的左上角使用的点。 如果未指定,则使用元素的一些可见点。138 x <float>139 y <float>140 :param timeout: 以毫秒为单位的最长时间,默认为 30 秒,传递 0 以禁用超时。141 可以使用 browser_context.set_default_timeout(timeout) 或 page.set_default_timeout(timeout) 方法更改默认值。142 """143 element = self._find_element_cross_frame(selector)144 element.dblclick(145 selector=selector,146 modifiers=modifiers,147 position=position,148 delay=delay,149 button=button,150 timeout=timeout,151 force=force,152 no_wait_after=no_wait_after,153 )154 def dispatch_event(155 self,156 selector: str,157 *,158 event_type: str = None,159 event_init: Dict = None,160 ) -> NoneType:161 """触发事件。162 下面的代码片段在元素上调度点击事件。163 无论元素的可见性状态如何,点击事件都会被调度。164 这等同于调用165 [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click)。166 ```py167 page.dispatch_event(\"button#submit\", \"click\")168 ```169 在后台,它根据给定的 `type` 创建一个事件实例,并使用 `eventInit` 属性对其进行初始化170 并在元素上调度它。事件默认为“已组合”、“可取消”和“冒泡”。171 如果你希望将活动对象传递到事件中,还可以指定 `JSHandle` 作为属性值:172 ```py173 # 请注意,只能在 Chromium 和 firefox 中创建 data_transfer174 data_transfer = page.evaluate_handle(\"new DataTransfer()\")175 page.dispatch_event(\"#source\", \"dragstart\", { \"dataTransfer\": data_transfer })176 ```177 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。178 :param event_type: DOM 事件类型:“click”、“dragstart”等。179 :param event_init: 可选的特定于事件的初始化属性。180 """181 element = self._find_element_cross_frame(selector)182 element.dispatch_event(183 type=event_type,184 event_init=event_init,185 )186 def drag_and_drop(187 self,188 source: str,189 target: str,190 source_position: Position = None,191 target_position: Position = None,192 timeout: float = None,193 ):194 """执行从 `selector_from` 选择的元素到 `selector_to` 选择的元素的拖放操作。195 该方法不支持跨Frame搜索元素196 :param source: 起点元素197 :param target: 终点元素198 :param source_position: 在该点相对于元素的填充框的左上角单击源元素。 如果未指定,则使用元素的某些可见点。199 :param target_position: 此时相对于元素填充框的左上角落在目标元素上。 如果未指定,则使用元素的某些可见点。200 :param timeout: 以毫秒为单位的最长时间,默认为 30 秒,传递 0 以禁用超时。可以使用201 browser_context.set_default_timeout(timeout)202 或 page.set_default_timeout(timeout) 方法更改默认值。203 """204 if ">>>" in source or ">>>" in target:205 unsupported_selector_engine = Error("该方法不支持跨 Frame 搜索语法。")206 raise unsupported_selector_engine207 self._obj.drag_and_drop(208 source=source,209 target=target,210 source_position=source_position,211 target_position=target_position,212 timeout=timeout,213 )214 def fill(215 self,216 selector: str,217 value: str,218 *,219 no_wait_after: bool = None,220 timeout: float = None,221 clear: bool = True,222 ) -> NoneType:223 """清空 `selector` 找到的文本字段,然后使用 `value` 填充它。224 此方法等待元素匹配选择器,等待可操作性检查,聚焦元素,填充它并在填充后触发输入事件。225 如果匹配选择器的元素不是 input 、textarea 或 contenteditable 元素,则此方法会引发错误。226 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。227 :param value: 为 input 、textarea 或 contenteditable 元素填充的值。228 :param no_wait_after: 启动导航的操作正在等待这些导航发生并等待页面开始加载。229 可以通过设置此标志选择退出等待。230 只需要在特殊情况下使用此选项,例如导航到无法访问的页面。231 默认为 false。232 :param timeout: 以毫秒为单位的最长时间,默认为 30 秒,传递 0 以禁用超时。可以使用233 browser_context.set_default_timeout(timeout)234 或 page.set_default_timeout(timeout) 方法更改默认值。235 :param clear: 如果在填充之前不应清除该字段,则设置为 false。 默认为 true。236 """237 element = self._find_element_cross_frame(selector)238 if clear:239 # 清空240 element.fill(241 value='',242 force=True,243 no_wait_after=no_wait_after,244 timeout=timeout,245 )246 # 填充247 element.fill(248 value=value,249 force=True,250 no_wait_after=no_wait_after,251 timeout=0,252 )253 def focus(self, selector: str):254 """此方法使用选择器 `selector` 获取元素并聚焦它。255 如果没有与选择器匹配的元素,该方法将等待匹配元素出现在 DOM 中。256 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。257 """258 element = self._find_element_cross_frame(selector)259 element.focus()260 def get_attribute(self, selector: str, name: str) -> Union[NoneType, str]:261 """返回元素属性值。262 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。263 :param name: 要获取其值的属性名称。264 """265 element = self._find_element_cross_frame(selector)266 return element.get_attribute(name)267 def get_table_cell(self, row_header: str, column_headers: List[str] = None):268 """获得单元格。269 如果有一个东西看起来像二维表,那么就可以使用行标题或列标题去取得单元格。270 如果不提供 `column_headers` ,那么将返回文本值匹配 `row_header` 的元素右侧的一个元素。271 :param column_headers: 列标题272 :param row_header: 行标题273 """274 def get_top_column_header_element(cell_text, limit_x):275 __column_header_elements = self._obj.query_selector_all(f"text='{cell_text}'")276 for __column_header_element in __column_header_elements:277 if __column_header_element.bounding_box()["x"] >= limit_x:278 return __column_header_element279 def get_target_column_header_element(cell_text, limit_min_x, limit_max_x):280 __column_header_elements = self._obj.query_selector_all(f"text='{cell_text}'")281 for __column_header_element in __column_header_elements:282 if (283 __column_header_element.bounding_box()["x"] >= limit_min_x284 and __column_header_element.bounding_box()["x"]285 + __column_header_element.bounding_box()["width"] <= limit_max_x286 ):287 return __column_header_element288 row_header_element = self._obj.query_selector(f"text='{row_header}'")289 if not column_headers:290 return self._obj.query_selector(f"*:right-of(:text('{row_header}'))")291 row_header_element_box = row_header_element.bounding_box()292 row_header_element_position = Position(293 x=row_header_element_box["x"] + row_header_element_box["width"] / 2,294 y=row_header_element_box["y"] + row_header_element_box["height"] / 2295 )296 column_min_x = row_header_element_box["x"] + row_header_element_box["width"]297 if len(column_headers) > 1:298 top_column_header_element = get_top_column_header_element(column_headers[0], column_min_x)299 coordinate_range = (300 top_column_header_element.bounding_box()["x"],301 top_column_header_element.bounding_box()["x"] + top_column_header_element.bounding_box()["width"]302 )303 target_column_header_element = get_target_column_header_element(304 column_headers[1],305 coordinate_range[0],306 coordinate_range[1]307 )308 else:309 target_column_header_element = get_top_column_header_element(column_headers[0], column_min_x)310 target_column_header_element_position = Position(311 x=target_column_header_element.bounding_box()["x"] + target_column_header_element.bounding_box()[312 "width"] / 2,313 y=target_column_header_element.bounding_box()["y"] + target_column_header_element.bounding_box()[314 "height"] / 2315 )316 cell_position = Position(317 x=target_column_header_element_position.get("x"),318 y=row_header_element_position.get("y")319 )320 return self._obj.evaluate_handle(321 f"document.elementFromPoint({cell_position.get('x')}, {cell_position.get('y')})")322 def go_back(323 self,324 timeout: float = None,325 wait_until: Literal["domcontentloaded", "load", "networkidle"] = None326 ):327 """导航到历史记录的上一页。328 返回主要资源响应。329 在多次重定向的情况下,导航将使用上次重定向的响应进行解析。330 如果不能返回,则返回 null。331 :param timeout:最大操作时间以毫秒为单位,默认为 30 秒,传递 0 以禁用超时。332 可以使用 browser_context.set_default_navigation_timeout(timeout)、333 browser_context.set_default_timeout(timeout)、334 page.set_default_navigation_timeout(timeout)335 或 page.set_default_timeout(timeout) 方法更改默认值。336 :param wait_until: <"load"|"domcontentloaded"|"networkidle"> 当认为操作成功时,默认加载。 事件可以是:#337 'domcontentloaded' - 当 DOMContentLoaded 事件被触发时,认为操作完成。338 'load' - 当加载事件被触发时,认为操作已经完成。339 'networkidle' - 当至少 500 毫秒没有网络连接时,认为操作完成。340 """341 if type(self._obj).__name__ == "Page":342 return self._obj.go_back(343 timeout=timeout,344 wait_until=wait_until,345 )346 elif type(self._obj).__name__ == "Frame":347 return self._obj.page.go_back(348 timeout=timeout,349 wait_until=wait_until,350 )351 else:352 raise TypeError(f"{self._obj}的类型应当是 Page 类型或 Frame 类型。")353 def go_forward(354 self,355 timeout: float = None,356 wait_until: Literal["domcontentloaded", "load", "networkidle"] = None357 ):358 """导航到历史记录的下一页。359 返回主要资源响应。360 在多次重定向的情况下,导航将使用上次重定向的响应进行解析。361 如果不能返回,则返回 null。362 :param timeout:最大操作时间以毫秒为单位,默认为 30 秒,传递 0 以禁用超时。363 可以使用 browser_context.set_default_navigation_timeout(timeout)、364 browser_context.set_default_timeout(timeout)、365 page.set_default_navigation_timeout(timeout)366 或 page.set_default_timeout(timeout) 方法更改默认值。367 :param wait_until: <"load"|"domcontentloaded"|"networkidle"> 当认为操作成功时,默认加载。 事件可以是:#368 'domcontentloaded' - 当 DOMContentLoaded 事件被触发时,认为操作完成。369 'load' - 当加载事件被触发时,认为操作已经完成。370 'networkidle' - 当至少 500 毫秒没有网络连接时,认为操作完成。371 """372 if type(self._obj).__name__ == "Page":373 return self._obj.go_forward(374 timeout=timeout,375 wait_until=wait_until,376 )377 elif type(self._obj).__name__ == "Frame":378 return self._obj.page.go_forward(379 timeout=timeout,380 wait_until=wait_until,381 )382 else:383 raise TypeError(f"{self._obj}的类型应当是 Page 类型或 Frame 类型。")384 def goto(385 self,386 url: str,387 *,388 timeout: float = None,389 wait_until: Literal["domcontentloaded", "load", "networkidle"] = None,390 referer: str = None391 ):392 """导航到 `url`393 返回主要资源响应。 在多次重定向的情况下,导航将使用上次重定向的响应进行解析。394 如果出现以下情况,该方法将抛出错误:395 存在 SSL 错误(例如,在自签名证书的情况下)。396 目标网址无效。397 导航期间超时。398 远程服务器没有响应或无法访问。399 主资源加载失败。400 当远程服务器返回任何有效的 HTTP 状态代码时,该方法不会抛出错误,包括 404“未找到”和 500“内部服务器错误”。401 可以通过调用 response.status 来检索此类响应的状态代码。402 注意:403 该方法要么抛出错误,要么返回主资源响应。 唯一的例外是导航到 about:blank 或导航到具有不同散列的相同 URL,这将成功并返回 null。404 :param url:页面导航到的 URL。 网址应包括方案,例如 https://。405 当通过上下文选项提供 base_url 并且传递的 URL 是路径时,它会通过新的 URL() 构造函数合并。406 :param timeout: 最大操作时间以毫秒为单位,默认为 30 秒,传递 0 以禁用超时。407 可以使用 browser_context.set_default_navigation_timeout(timeout)、408 browser_context.set_default_timeout(timeout)、409 page.set_default_navigation_timeout(timeout)410 或 page.set_default_timeout(timeout) 方法更改默认值。411 :param wait_until: <"load"|"domcontentloaded"|"networkidle"> 当认为操作成功时,默认加载。 事件可以是:#412 'domcontentloaded' - 当 DOMContentLoaded 事件被触发时,认为操作完成。413 'load' - 当加载事件被触发时,认为操作已经完成。414 'networkidle' - 当至少 500 毫秒没有网络连接时,认为操作完成。415 :param referer: 引用标头值。 如果提供,它将优先于 page.set_extra_http_headers(headers) 设置的引用标头值.416 """417 return self._obj.goto(418 url=url,419 timeout=timeout,420 wait_until=wait_until,421 referer=referer,422 )423 def hover(424 self,425 selector: str,426 timeout: float = None,427 modifiers: Optional[428 List[Literal["Alt", "Control", "Meta", "Shift"]]429 ] = None,430 position: Position = None,431 ):432 """鼠标悬停433 此方法通过执行以下步骤将鼠标悬停在元素上:434 等待对元素的可操作性检查。435 如果需要,将元素滚动到视图中。436 使用 page.mouse 将鼠标悬停在元素的中心或指定位置上。437 等待启动的导航成功或失败438 :param position: 相对于元素填充框的左上角使用的点。 如果未指定,则使用元素的一些可见点。439 :param modifiers: 要按下的修饰键。 确保在操作期间仅按下这些修饰符,然后将当前修饰符恢复回来。 如果未指定,则使用当前按下的修饰符440 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。441 :param timeout: 最大操作时间以毫秒为单位,默认为 30 秒,传递 0 以禁用超时。442 可以使用 browser_context.set_default_navigation_timeout(timeout)、443 browser_context.set_default_timeout(timeout)、444 page.set_default_navigation_timeout(timeout)445 或 page.set_default_timeout(timeout) 方法更改默认值。446 """447 element = self._find_element_cross_frame(selector=selector)448 element.hover(449 modifiers=modifiers,450 timeout=timeout,451 position=position,452 )453 def inner_html(self, selector: str) -> str:454 """元素的 innerHTML 值。455 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。456 """457 element = self._find_element_cross_frame(selector)458 return element.inner_html()459 def inner_text(self, selector: str) -> str:460 """元素的 innerText 值。461 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。462 """463 element = self._find_element_cross_frame(selector)464 return element.inner_text()465 def input_value(self, selector: str, timeout: float = None) -> str:466 """元素的 value 属性的值。467 :param selector: 用于搜索元素的选择器。 如果有多个元素满足选择器,将使用第一个。468 :param timeout: 最大操作时间以毫秒为单位,默认为 30 秒,传递 0 以禁用超时。469 可以使用 browser_context.set_default_navigation_timeout(timeout)、470 browser_context.set_default_timeout(timeout)、471 page.set_default_navigation_timeout(timeout)472 或 page.set_default_timeout(timeout) 方法更改默认值473 """474 element = self._find_element_cross_frame(selector)475 return element.input_value(timeout=timeout)476 def is_checked(self, selector: str) -> bool:477 """返回是否选中元素。如果元素不是复选框或单选输入,则引发异常。"""478 return self._find_element_cross_frame(selector).is_checked()479 def is_disabled(self, selector: str) -> bool:480 """返回元素是否被禁用,与启用相反。"""481 return self._find_element_cross_frame(selector).is_disabled()482 def is_editable(self, selector: str) -> bool:483 """返回元素是否可编辑。"""484 return self._find_element_cross_frame(selector).is_editable()485 def is_enabled(self, selector: str) -> bool:486 """返回元素是否被启用。"""487 return self._find_element_cross_frame(selector).is_enabled()488 def is_hidden(self, selector: str) -> bool:489 """返回元素是否隐藏,与可见相反。 不匹配任何元素的选择器被认为是隐藏的。"""490 return self._find_element_cross_frame(selector).is_hidden()491 def is_visible(self, selector: str) -> bool:492 """返回元素是否可见。 不匹配任何元素的选择器被认为是不可见的。"""493 return self._find_element_cross_frame(selector).is_visible()494 def press(495 self,496 selector: str,497 key: str,498 delay: float = None,499 timeout: float = None,500 no_wait_after: bool = None,501 ) -> None:502 """模拟手动输入。503 聚焦元素,然后使用keyboard.down(key) 和keyboard.up(key)。504 key 可以指定预期的 keyboardEvent.key 值或要为其生成文本的单个字符。 可以在此处找到键值的超集。 键的例子是:505 F1 - F12, Digit0- Digit9, KeyA- KeyZ, 反引号, 减号, 等号, 反斜杠, Backspace, Tab, Delete, Escape, ArrowDown, End,506 Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp, 等等。507 还支持以下修改快捷键:Shift、Control、Alt、Meta、ShiftLeft。508 按住 Shift 键将键入与大写键对应的文本。509 如果键是单个字符,则它区分大小写,因此值a和A将生成不同的文本。510 也支持快捷键,例如键:“Control+o”或键:“Control+Shift+T”。 当使用修饰符指定时,在按下后续键的同时按下并按住修饰符。511 :param selector: 用于搜索元素的选择器。如果有多个元素满足选择器,将使用第一个。512 :param key: 要按下的键的名称或要生成的字符,例如 ArrowLeft 或 a。513 :param delay: 在 keydown 和 keyup 之间等待的时间(以毫秒为单位)。 默认为 0。514 :param timeout: 以毫秒为单位的最长时间,默认为 30 秒,传递 0 以禁用超时。515 可以使用 browser_context.set_default_timeout(timeout) 或 page.set_default_timeout(timeout) 方法更改默认值516 :param no_wait_after: 启动导航的操作正在等待这些导航发生并等待页面开始加载。 可以通过设置此标志选择退出等待。517 只需要在特殊情况下使用此选项,例如导航到无法访问的页面。 默认为假。518 """519 element = self._find_element_cross_frame(selector)520 element.press(521 key=key,522 delay=delay,523 timeout=timeout,524 no_wait_after=no_wait_after,525 )526 def select_option(527 self,528 selector: str,529 value: Union[str, List[str]] = None,530 index: Union[int, List[int]] = None,531 label: Union[str, List[str]] = None,532 option_element: Union["ElementHandle", List["ElementHandle"]] = None,533 timeout: float = None,534 ) -> List[str]:535 """此方法等待元素匹配选择器,等待可操作性检查,等待所有指定的选项都出现在 <select> 元素中并选择这些选项。536 如果目标元素不是 <select> 元素,则此方法会引发错误。 但是,如果该元素位于具有关联控件的 <label> 元素内,则将使用该控件。537 返回已成功选择的选项值数组。538 一旦选择了所有提供的选项,就会触发更改和输入事件。539 :param selector:540 :param value: 按值选择的选项。 可选的。541 如果 <select> 具有 multiple 属性,则选择所有给定的选项,否则仅选择与传递的选项之一匹配的第一个选项。542 :param index: 按索引选择的选项。 可选的。543 :param label: 按标签选择的选项。 可选的。544 如果 <select> 具有 multiple 属性,则选择所有给定的选项,否则仅选择与传递的选项之一匹配的第一个选项。545 :param option_element: 按 ElementHandle 实例选择选项。 可选的。546 :param timeout: 以毫秒为单位的最长时间,默认为 30 秒,传递 0 以禁用超时。547 可以使用 browser_context.set_default_timeout(timeout) 或 page.set_default_timeout(timeout) 方法更改默认值。548 """549 element = self._find_element_cross_frame(selector=selector)550 return element.select_option(551 timeout=timeout,552 element=option_element,553 index=index,554 value=value,555 label=label556 )557 def select_option_for_ant(558 self,559 selector: str,560 index: int = None,561 label: str = None,...

Full Screen

Full Screen

test_snmp.py

Source:test_snmp.py Github

copy

Full Screen

...39 while (self.snmp_engine.poll() > 0):40 self.zmq_core.poll(0.1)41 def test_valid_timeout(self):42 """ Valid timeout value updates default SNMP timeout """43 self.snmp_engine.set_default_timeout("123")44 eq_(self.snmp_engine.default_timeout, 123)45 def test_bad_timeout(self):46 """ Invalid timeout value doesnt change timeout """47 default_timeout = self.snmp_engine.default_timeout48 self.snmp_engine.set_default_timeout("Not a number")49 eq_(self.snmp_engine.default_timeout, default_timeout)50 def test_v1get(self):51 """ Simple SNMP v1 fetch of SysObjectID """52 self.set_host(1, 'public')53 assert(self.snmp_engine.get_str(54 self.test_host, self.sysobjid_oid, my_callback1, obj=self))55 self.poll()56 eq_(self.results, [self.expected_sysobjid, ])57 def test_v2get(self):58 """ Simple SNMP v2 fetch of SysObjectID """59 self.set_host(2, 'public')60 self.snmp_engine.get_str(61 self.test_host, self.sysobjid_oid, my_callback1, obj=self)62 self.poll()63 eq_(self.results, [self.expected_sysobjid, ])64 def test_v1_default_bad_comm(self):65 """ Simple SNMP v1 fetch returns default with bad community"""66 self.set_host(1, 'badcomm')67 self.snmp_engine.set_default_timeout(1)68 self.snmp_engine.get_str(69 self.test_host, self.sysobjid_oid, my_callback1,70 default="42", obj=self)71 self.poll()72 eq_(self.results, ["42"])73 def test_v2_default_bad_comm(self):74 """ Simple SNMP v2c fetch returns default with bad community"""75 self.set_host(2, 'badcomm')76 self.snmp_engine.set_default_timeout(1)77 self.snmp_engine.get_str(78 self.test_host, self.sysobjid_oid, my_callback1,79 default="42", obj=self)80 self.poll()81 eq_(self.results, ["42"])82 def test_v1_default_bad_oid(self):83 """ Simple SNMP v1 fetch returns default with bad OID"""84 self.set_host(1, 'public')85 self.snmp_engine.set_default_timeout(1)86 self.snmp_engine.get_str(87 self.test_host, '1.3.6.42.41.40', my_callback1,88 default="42", obj=self)89 self.poll()90 eq_(self.results, ["42"])91 def test_v2_default_bad_oid(self):92 """ Simple SNMP v2c fetch returns default with bad OID"""93 self.set_host(2, 'public')94 self.snmp_engine.set_default_timeout(1)95 self.snmp_engine.get_str(96 self.test_host, '1.3.6.42.41.40', my_callback1,97 default="42", obj=self)98 self.poll()99 eq_(self.results, ["42"])100 def test_v1_table(self):101 """ SNMP v1 table fetch - uses ifTable.ifIndex """102 self.set_host(1, 'public')103 self.snmp_engine.set_default_timeout(1)104 # Get size of iftable105 self.snmp_engine.get_int(106 self.test_host, '1.3.6.1.2.1.2.1.0', my_callback1, obj=self)107 self.poll()108 eq_(len(self.results), 1)109 table_length = self.results[0]110 self.snmp_engine.get_table(111 self.test_host, ('1.3.6.1.2.1.2.2.1.1',), my_callback1,112 table_trim=1, obj=self)113 self.poll()114 eq_(len(self.results),2)115 eq_(len(self.results[1][0]),table_length)116 for oid,val in self.results[1][0].items():117 assert(oid == val)...

Full Screen

Full Screen

connection.py

Source:connection.py Github

copy

Full Screen

...50 lazy_connect=lazy_connect,51 auth_provider=auth_provider,52 port=cluster_conf[ConfigKey.PORT])53 connection_timeout = cluster_conf.get(ConfigKey.DEFAULT_TIMEOUT, 10.0)54 set_default_timeout(cqlengine_connection.get_connection(), connection_timeout)55 _connection_setup = True56 return True57 except KeyError as exc:58 LOG.debug("Got exception %s with args %s while trying to setup Cassandra connection", exc, exc.args)59 return False60def set_default_timeout(conn=None, default_timeout_in_s=10.0):61 """Sets the default connection timeout that cqlengine uses.62 :param conn: The connection to set default_timeout on.63 :type conn: cassandra.cqlengine.connection.Connection64 :param default_timeout_in_s: The default connection timeout to use in seconds. This timeout will be used unless65 a different timeout is explicitly used on a specific query66 :type default_timeout_in_s: float67 """68 if conn is None:69 conn = cqlengine_connection.get_connection()70 if not conn.session:71 # Session is being loaded lazily, so need to assign the timeout at first session creation72 # Monkey Patch the handle_lazy_connect method so we can intercept the initial call and do session setup73 old_handle_lazy_connect = conn.handle_lazy_connect74 def cb_handle_lazy_connect():75 """handle_lazy_connect monkey patch interceptor method which assigns the default timeout upon76 lazy session creation of cqlengine77 """78 LOG.debug("Intercepted lazy cqlengine connect call")79 conn.handle_lazy_connect = old_handle_lazy_connect80 old_handle_lazy_connect()81 set_default_timeout(default_timeout_in_s)82 conn.handle_lazy_connect = cb_handle_lazy_connect83 else:84 LOG.debug("Default connection timeout set to %s", default_timeout_in_s)85 conn.session.default_timeout = default_timeout_in_s86def is_cassandra_available():87 """88 :return: Whether or not Cassandra is currently available.89 :rtype: bool90 """91 cass_setup = False92 try:93 cass_setup = setup_connection_from_config()94 except AttributeError:95 pass...

Full Screen

Full Screen

ggogle_tans.py

Source:ggogle_tans.py Github

copy

Full Screen

...10 :return: 返回两个 list11 """12 browser = playwright.chromium.launch(headless=False)13 context = browser.new_context()14 context.set_default_timeout(0)15 # Open new page16 page1 = context.new_page()17 page1.set_default_timeout(0)18 page1.set_default_navigation_timeout(0)19 page2 = context.new_page()20 page2.set_default_timeout(0)21 page2.set_default_navigation_timeout(0)22 # Go to https://translate.google.cn/?sl=en&tl=zh-CN&op=translate23 page1.goto("https://translate.google.cn/?sl=en&tl=zh-CN&op=translate")24 page2.goto("https://translate.google.cn/?sl=en&tl=zh-CN&op=translate")25 # Click [aria-label="原文"]26 # page.click("[aria-label=\"原文\"]")27 # Fill [aria-label="原文"]28 # 一个简单的并行,把需要翻译的内容分成两部分,分开在两个网页上翻译29 result1 = []30 result2 = []31 trans_num = len(trans_list)32 trans_lis_1 = trans_list[0:trans_num // 2]33 trans_lis_2 = trans_list[trans_num // 2:trans_num]34 for i,j in zip(trans_lis_1, trans_lis_2):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful