How to retrieve the text of a WebElement using Selenium – Python

The desired element is a dynamic element so to extract the text within the element you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following solutions: Using CSS_SELECTOR: print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, “p.value.noWrap[data-bind$=’MarketValue’]”))).get_attribute(“innerHTML”)) Using XPATH: print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, “//p[@class=”value noWrap” and contains(@data-bind,’MarketValue’)]”))).get_attribute(“innerHTML”)) Note : You have to add the following imports : … Read more

How can I reconnect to the browser opened by webdriver with selenium?

Yes, that’s actually quite easy to do. A selenium <-> webdriver session is represented by a connection url and session_id, you just reconnect to an existing one. Disclaimer – the approach is using selenium internal properties (“private”, in a way), which may change in new releases; you’d better not use it for production code; it’s … Read more

tech