Variant on query_selector_all and find_elements_by_text. This variant takes either selector or text, and will block until the requested element(s) are found. It will block for a maximum of seconds, after which a TimeoutError will be raised.
(
self,
selector: Optional[str] = "",
text: Optional[str] = "",
timeout: Optional[Union[int, float]] = 10,
)
| 1071 | ) |
| 1072 | |
| 1073 | async def wait_for( |
| 1074 | self, |
| 1075 | selector: Optional[str] = "", |
| 1076 | text: Optional[str] = "", |
| 1077 | timeout: Optional[Union[int, float]] = 10, |
| 1078 | ) -> element.Element: |
| 1079 | """ |
| 1080 | Variant on query_selector_all and find_elements_by_text. |
| 1081 | This variant takes either selector or text, |
| 1082 | and will block until the requested element(s) are found. |
| 1083 | It will block for a maximum of <timeout> seconds, |
| 1084 | after which a TimeoutError will be raised. |
| 1085 | :param selector: css selector |
| 1086 | :param text: text |
| 1087 | :param timeout: |
| 1088 | :return: Element |
| 1089 | :raises: asyncio.TimeoutError |
| 1090 | """ |
| 1091 | loop = asyncio.get_running_loop() |
| 1092 | now = loop.time() |
| 1093 | if selector: |
| 1094 | item = await self.query_selector(selector) |
| 1095 | while not item: |
| 1096 | item = await self.query_selector(selector) |
| 1097 | if loop.time() - now > timeout: |
| 1098 | raise asyncio.TimeoutError( |
| 1099 | "Time ran out while waiting for: {%s}" % selector |
| 1100 | ) |
| 1101 | await self.sleep(0.068) |
| 1102 | return item |
| 1103 | if text: |
| 1104 | item = await self.find_element_by_text(text) |
| 1105 | while not item: |
| 1106 | item = await self.find_element_by_text(text) |
| 1107 | if loop.time() - now > timeout: |
| 1108 | raise asyncio.TimeoutError( |
| 1109 | "Time ran out while waiting for: {%s}" % text |
| 1110 | ) |
| 1111 | await self.sleep(0.068) |
| 1112 | return item |
| 1113 | |
| 1114 | async def set_attributes(self, selector, attribute, value): |
| 1115 | """This method uses JavaScript to set/update a common attribute. |
no test coverage detected