Every line of 'driver findelement by xpath' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
5 def find_element(driver, locator): 6 return WebDriverWait(driver, 2).until( 7 EC.presence_of_element_located(locator))
15 def text(self, selector): 16 return selector.text
421 def is_element_not_present_by_text(self, text, wait_time=None): 422 return self.is_element_not_present(self.find_by_text, text, wait_time)
421 def wait_element_disappears_by_xpath(self, selector, criterium="presence", 422 appear_timeout=None, disappear_timeout=None): 423 return self.wait_element_disappears('xpath', selector, criterium, appear_timeout, 424 disappear_timeout)
227 def waitForElements(self, css_selector, timeout=DEFAULT_WAIT_TIMEOUT, 228 visible=None): 229 """ Waits for DOM elements matching the provided CSS selector to be 230 available. 231 232 Args: 233 - css_selector: CSS selector string 234 235 Kwargs: 236 - timeout: Operation timeout in seconds 237 - visible: Ensure elements visibility status: 238 * True: wait for visible elements only 239 * False: wait for invisible elements only 240 * None: skip visibility status checks 241 242 Returns: List of DOM elements 243 """ 244 def get_element_checker(driver, visible): 245 locator = (By.CSS_SELECTOR, css_selector) 246 if visible is True: 247 return EC.visibility_of_element_located(locator) 248 if visible is False: 249 return EC.invisibility_of_element_located(locator) 250 return lambda _: driver.find_elements_by_css_selector(css_selector) 251 252 message = u"Couldn't find elems matching %s (visibility check: %s)" % ( 253 css_selector, visible) 254 WebDriverWait(self, timeout, poll_frequency=.25).until( 255 get_element_checker(self, visible), message=message) 256 257 return self.find_elements_by_css_selector(css_selector)
80 def wait_on_element(driver, xpath, timeout=120): 81 num = 0 82 while is_element_present(driver, xpath) is False: 83 if num >= timeout: 84 return False 85 else: 86 num += 1 87 time.sleep(1) 88 return True
340 def ensure_element_by_xpath(self, selector, criterium="presence", timeout=None): 341 return self.ensure_element('xpath', selector, criterium, timeout)
314 def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR, 315 timeout=settings.LARGE_TIMEOUT): 316 """ 317 Searches for the specified element by the given selector. Returns the 318 element object if the text matches exactly with the text in the element, 319 and the text is visible. 320 Raises an exception if the text or element do not appear 321 in the specified timeout. 322 @Params 323 driver - the webdriver object (required) 324 text - the exact text that is expected for the element (required) 325 selector - the locator for identifying the page element (required) 326 by - the type of selector being used (Default: By.CSS_SELECTOR) 327 timeout - the time to wait for elements in seconds 328 @Returns 329 A web element object that contains the text searched for 330 """ 331 element = None 332 start_ms = time.time() * 1000.0 333 stop_ms = start_ms + (timeout * 1000.0) 334 for x in range(int(timeout * 10)): 335 try: 336 element = driver.find_element(by=by, value=selector) 337 if element.is_displayed() and text.strip() == element.text.strip(): 338 return element 339 else: 340 element = None 341 raise Exception() 342 except Exception: 343 now_ms = time.time() * 1000.0 344 if now_ms >= stop_ms: 345 break 346 time.sleep(0.1) 347 plural = "s" 348 if timeout == 1: 349 plural = "" 350 if not element: 351 raise ElementNotVisibleException( 352 "Expected exact text {%s} for {%s} was not visible " 353 "after %s second%s!" % (text, selector, timeout, plural))
54 def find_by_text(self, tag, text): 55 return self.wait_until_visible((By.XPATH,"//" + tag + "[contains(.,'" + text + "')]"))
254 def get_element_by_xpath(self, selector): 255 """ 256 Gets an element using an xPath selector. 257 """ 258 raise NotImplementedError( 259 "This browser doesn't support getting elements by xpath")