How to use is_element_in_an_iframe method in SeleniumBase

Best Python code snippet using SeleniumBase

web_node.py

Source:web_node.py Github

copy

Full Screen

...497 def wait_until_loaded_succeeded(self,498 timeout: pb_types.NumberType = None,499 raise_error: bool = True,500 force_count_not_zero: bool = True, ) -> bool:501 element_in_iframe = self.is_element_in_an_iframe()502 # Handle special case: if locator is None, no valid_count validation.503 if self.locator is not None:504 # Handle frames505 if element_in_iframe is True:506 for node in self.path[:-1]:507 node: GenericNode508 if node.is_iframe() is True:509 node.switch_to_frame(timeout)510 valid_count = self.wait_until_valid_count_succeeded(timeout, raise_error, force_count_not_zero)511 if valid_count is False:512 if element_in_iframe is True:513 self.switch_to_default_content()514 return False515 children: list[GenericNode] = []516 if self.is_multiple:517 multiples = self.get_multiple_nodes()518 for node in multiples:519 node.wait_until_loaded_succeeded(timeout, raise_error)520 children = children + list(node.children)521 else:522 children = list(self.children)523 for node in children:524 loaded = node.wait_until_loaded_succeeded(timeout, raise_error, force_count_not_zero=False)525 if loaded is False:526 if element_in_iframe is True:527 self.switch_to_default_content()528 return False529 else:530 if element_in_iframe is True:531 self.switch_to_default_content()532 # Custom wait_until_loaded logic533 try:534 self.override_wait_until_loaded(timeout)535 except Exception as e:536 if raise_error is True:537 raise e538 else:539 return False540 # All validations passed541 return True542 def override_wait_until_loaded(self, timeout: pb_types.NumberType = None) -> None:543 pass544 ######################545 # get/set field value546 ######################547 def override_get_field_value(self, timeout: pb_types.NumberType = None) -> Any:548 return self.default_get_field_value(timeout)549 def override_set_field_value(self, value: Any, timeout: pb_types.NumberType = None) -> None:550 self.default_set_field_value(value, timeout)551 def get_field_value(self, timeout: pb_types.NumberType = None) -> Any:552 for node in self.path[:-1]:553 node: GenericNode554 rel_name = node.relative_name_of_descendant(self)555 method = getattr(node, f"get_{rel_name}_field_value", None)556 if method is not None:557 return method(timeout)558 else:559 return self.override_get_field_value(timeout)560 def set_field_value(self, value: Any, timeout: pb_types.NumberType = None) -> None:561 if value is None:562 return563 for node in self.path[:-1]:564 node: GenericNode565 rel_name = node.relative_name_of_descendant(self)566 method = getattr(node, f"set_{rel_name}_field_value", None)567 if method is not None:568 method(value, timeout)569 return570 else:571 self.override_set_field_value(value, timeout)572 def default_get_field_value(self, timeout: pb_types.NumberType = None) -> Any:573 if self.is_multiple:574 return [node.default_get_field_value(timeout) for node in self.get_multiple_nodes()]575 else:576 tag_name = self.get_tag_name(timeout)577 text = self.get_text(timeout)578 if pb_util.caseless_equal(tag_name, "input"):579 element_type = self.get_attribute("type", timeout, hard_fail=False)580 if isinstance(element_type, str) \581 and pb_util.caseless_text_in_texts(element_type, ["checkbox", "radio"]):582 return self.is_selected()583 elif text in [None, ""]:584 return self.get_attribute("value", timeout, hard_fail=False)585 else:586 return text587 elif pb_util.caseless_equal(tag_name, "select"):588 return self.get_selected_options()589 else:590 return text591 def default_set_field_value(self, value: Any, timeout: pb_types.NumberType = None) -> None:592 if self.is_multiple and isinstance(value, list):593 nodes = self.get_multiple_nodes()594 for i in range(len(value)):595 nodes[i].default_set_field_value(value[i], timeout)596 else:597 tag_name = self.get_tag_name(timeout)598 element_type = self.get_attribute("type", timeout, hard_fail=False)599 if pb_util.caseless_equal(tag_name, "input"):600 if isinstance(element_type, str) and pb_util.caseless_equal(element_type, "text"):601 self.update_text(str(value), timeout, retry=True)602 elif isinstance(element_type, str) and pb_util.caseless_equal(element_type, "checkbox"):603 if value is True or (isinstance(value, str)) and pb_util.caseless_equal(value, "true"):604 self.select_if_unselected()605 elif value is False or (isinstance(value, str) and pb_util.caseless_equal(value, "false")):606 self.unselect_if_selected()607 elif isinstance(value, str) and pb_util.caseless_equal(value, "toggle"):608 self.click()609 else:610 raise Exception(611 f"Do not know how to set value '{value}' to tag={tag_name} type={element_type}. "612 f"Node: {self}",613 )614 elif isinstance(element_type, str) and pb_util.caseless_equal(element_type, "radio"):615 if value is True or (isinstance(value, str) and pb_util.caseless_equal(value, "true")):616 self.select_if_unselected()617 else:618 raise Exception(619 f"Do not know how to set value '{value}' to tag={tag_name} type={element_type}. "620 f"Node: {self}",621 )622 elif isinstance(element_type, str) and pb_util.caseless_equal(element_type, "file"):623 self.choose_file(value)624 else:625 raise Exception(626 f"Do not know how to set value '{value}' to tag={tag_name} type={element_type}. Node: {self}",627 )628 elif pb_util.caseless_equal(tag_name, "select"):629 if isinstance(value, str):630 self.select_option_by_text(value, timeout)631 elif isinstance(value, int):632 self.select_option_by_index(value, timeout)633 elif isinstance(value, list):634 if len(value) == 0:635 self.deselect_all_options(timeout)636 else:637 for item in value:638 if isinstance(item, str):639 self.select_option_by_text(item, timeout)640 elif isinstance(item, int):641 self.select_option_by_index(item, timeout)642 else:643 raise Exception(644 f"Do not know how to set value '{value}' to tag={tag_name} type={element_type}. "645 f"Node: {self}",646 )647 else:648 self.update_text(str(value), timeout)649 def wait_until_field_value_succeeded(self,650 condition: Union[Callable[[Any], bool], Any],651 timeout: pb_types.NumberType = None,652 equals: bool = True,653 raise_error: bool = True) -> bool:654 if timeout is None:655 timeout = LARGE_TIMEOUT656 if raise_error is True:657 raise_error = f"Timeout in wait_until_field_value_is: " \658 f"condition={condition}, timeout={timeout}, equals={equals}. Node: {self}"659 else:660 raise_error = None661 if isinstance(condition, Callable):662 success, _ = pb_util.wait_until(lambda: condition(self.get_field_value(timeout)),663 timeout=timeout,664 equals=equals,665 raise_error=raise_error)666 return success667 else:668 success, _ = pb_util.wait_until(lambda: self.get_field_value(timeout),669 expected=condition,670 timeout=timeout,671 equals=equals,672 raise_error=raise_error)673 return success674 #######################675 # PomBaseCase methods676 #######################677 def count(self) -> int:678 return self.pbc.count(selector=self)679 def is_iframe(self, timeout: pb_types.NumberType = None) -> bool:680 return self.pbc.is_iframe(selector=self, timeout=timeout)681 def switch_to_default_content(self) -> None:682 self.pbc.switch_to_default_content()683 def get_tag_name(self, timeout: pb_types.NumberType = None) -> str:684 return self.pbc.get_tag_name(selector=self, timeout=timeout)685 def get_selected_options(self, timeout: pb_types.NumberType = None) -> list[str]:686 return self.pbc.get_selected_options(selector=self, timeout=timeout)687 def deselect_all_options(self, timeout: pb_types.NumberType = None) -> None:688 return self.pbc.deselect_all_options(selector=self, timeout=timeout)689 #######################690 # SeleniumBase methods691 #######################692 def click(self, timeout: pb_types.NumberType = None, delay: int = 0) -> None:693 self.pbc.click(selector=self, timeout=timeout, delay=delay)694 def slow_click(self, timeout: pb_types.NumberType = None) -> None:695 self.pbc.slow_click(selector=self, timeout=timeout)696 def double_click(self, timeout: pb_types.NumberType = None) -> None:697 return self.pbc.double_click(selector=self, timeout=timeout)698 def click_chain(self, timeout: pb_types.NumberType = None, spacing: int = 0) -> None:699 self.pbc.click_chain(selector=self, timeout=timeout, spacing=spacing)700 def add_text(self, text: str, timeout: pb_types.NumberType = None) -> None:701 self.pbc.add_text(selector=self, text=text, timeout=timeout)702 def update_text(self, text: str, timeout: pb_types.NumberType = None, retry: bool = False) -> None:703 self.pbc.update_text(selector=self, text=text, timeout=timeout, retry=retry)704 def submit(self) -> None:705 self.pbc.submit(selector=self)706 def clear(self, timeout: pb_types.NumberType = None) -> None:707 self.pbc.clear(selector=self, timeout=timeout)708 def focus(self, timeout: pb_types.NumberType = None) -> None:709 self.pbc.focus(selector=self, timeout=timeout)710 def is_element_present(self) -> bool:711 return self.pbc.is_element_present(selector=self)712 def is_element_visible(self) -> bool:713 return self.pbc.is_element_visible(selector=self)714 def is_element_enabled(self) -> bool:715 return self.pbc.is_element_enabled(selector=self)716 def is_text_visible(self, text: str) -> bool:717 return self.pbc.is_text_visible(text=text, selector=self)718 def get_text(self, timeout: pb_types.NumberType = None) -> str:719 return self.pbc.get_text(selector=self, timeout=timeout)720 def get_attribute(self,721 attribute: str,722 timeout: pb_types.NumberType = None,723 hard_fail: bool = True, ) -> Union[None, str, bool, int]:724 return self.pbc.get_attribute(selector=self, attribute=attribute, timeout=timeout, hard_fail=hard_fail)725 def set_attribute(self, attribute: str, value: Any, timeout: pb_types.NumberType = None) -> None:726 self.pbc.set_attribute(selector=self, attribute=attribute, value=value, timeout=timeout)727 def set_attributes(self, attribute: str, value: Any) -> None:728 self.pbc.set_attributes(selector=self, attribute=attribute, value=value)729 def remove_attribute(self, attribute: str, timeout: pb_types.NumberType = None) -> None:730 self.pbc.remove_attribute(selector=self, attribute=attribute, timeout=timeout)731 def remove_attributes(self, attribute: str) -> None:732 self.pbc.remove_attributes(selector=self, attribute=attribute)733 def get_property_value(self, property: str, timeout: pb_types.NumberType = None) -> str:734 return self.pbc.get_property_value(selector=self, property=property, timeout=timeout)735 def get_image_url(self, timeout: pb_types.NumberType = None) -> Optional[str]:736 return self.pbc.get_image_url(selector=self, timeout=timeout)737 def find_elements(self, limit: int = 0) -> list[WebElement]:738 return self.pbc.find_elements(selector=self, limit=limit)739 def find_visible_elements(self, limit: int = 0) -> list[WebElement]:740 return self.pbc.find_visible_elements(selector=self, limit=limit)741 def click_visible_elements(self, limit: int = 0, timeout: pb_types.NumberType = None) -> None:742 self.pbc.click_visible_elements(selector=self, limit=limit, timeout=timeout)743 def click_nth_visible_element(self, number, timeout: pb_types.NumberType = None) -> None:744 self.pbc.click_nth_visible_element(selector=self, number=number, timeout=timeout)745 def click_if_visible(self) -> None:746 self.pbc.click_if_visible(selector=self)747 def is_selected(self, timeout: pb_types.NumberType = None) -> bool:748 return self.pbc.is_selected(selector=self, timeout=timeout)749 def select_if_unselected(self) -> None:750 self.pbc.select_if_unselected(selector=self)751 def unselect_if_selected(self) -> None:752 self.pbc.unselect_if_selected(selector=self)753 def is_element_in_an_iframe(self) -> bool:754 if self.locator is None:755 if self.parent is None:756 return False757 else:758 parent: GenericNode = self.parent759 return parent.is_element_in_an_iframe()760 return self.pbc.is_element_in_an_iframe(selector=self)761 def switch_to_frame_of_element(self) -> Optional[str]:762 return self.pbc.switch_to_frame_of_element(selector=self)763 def hover_on_element(self) -> None:764 self.pbc.hover_on_element(selector=self)765 def hover_and_click(self,766 click_selector: Union[str, GenericNode],767 click_by: str = None,768 timeout: pb_types.NumberType = None, ) -> WebElement:769 return self.pbc.hover_and_click(770 hover_selector=self,771 click_selector=click_selector,772 click_by=click_by,773 timeout=timeout,774 )...

Full Screen

Full Screen

pombase_case.py

Source:pombase_case.py Github

copy

Full Screen

...700 def unselect_if_selected(self, selector, by=By.CSS_SELECTOR):701 selector, by = _recalculate_selector_by(selector, by)702 super().unselect_if_selected(selector, by)703 @overrides704 def is_element_in_an_iframe(self, selector, by=By.CSS_SELECTOR):705 selector, by = _recalculate_selector_by(selector, by)706 return super().is_element_in_an_iframe(selector, by)707 @overrides708 def switch_to_frame_of_element(self, selector, by=By.CSS_SELECTOR):709 selector, by = _recalculate_selector_by(selector, by)710 return super().switch_to_frame_of_element(selector, by)711 @overrides712 def hover_on_element(self, selector, by=By.CSS_SELECTOR):713 selector, by = _recalculate_selector_by(selector, by)714 super().hover_on_element(selector, by)715 @overrides716 def hover_and_click(self, hover_selector, click_selector, hover_by=By.CSS_SELECTOR, click_by=By.CSS_SELECTOR,717 timeout=None):718 hover_selector, hover_by = _recalculate_selector_by(hover_selector, hover_by)719 click_selector, click_by = _recalculate_selector_by(click_selector, click_by)720 return super().hover_and_click(hover_selector, click_selector, hover_by, click_by, timeout)...

Full Screen

Full Screen

test_package.py

Source:test_package.py Github

copy

Full Screen

...23 self.assert_element("div.withScreencast")24 self.assert_element("div.stApp")25 # github_gist26 self.assert_text("github_gist test")27 self.is_element_in_an_iframe("div.gist-file")28 self.is_element_in_an_iframe("div.gist-data")29 self.is_element_in_an_iframe("div.gist-meta")30 # gitlab_snippet31 self.assert_text("gitlab_snippet test")32 self.is_element_in_an_iframe("div.gitlab-embed-snippets")33 # pastebin_snippet34 self.assert_text("pastebin_snippet test")35 self.is_element_in_an_iframe("div.embedPastebin")36 # codepen_snippet37 self.assert_text("codepen_snippet test")38 self.is_element_in_an_iframe("div.cp_embed_wrapper")39 # ideone_snippet40 self.assert_text("ideone_snippet test")41 # TODO42 # tagmycode_snippet43 self.assert_text("tagmycode_snippet test")...

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