How To Extract Data From The Following Html?
The Html from where i want to extract data is:
Solution 1:
To extract the text Fiber är beställd till adressen. Tjänsterna kan du beställa när installationen är färdig. just from the 1st span only you need to induce WebDriverWait for the text to be present in the element and you can use the following solution:
Imports:
from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC
Line of code:
#Option 1 - text_to_be_present_in_element and CSS_SELECTORelement = WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, "div.infoMessageInner>p>span.ng-binding"), "Fiber är beställd till adressen")) #Option 2 - text_to_be_present_in_element_value and CSS_SELECTORelement = WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element_value((By.CSS_SELECTOR, "div.infoMessageInner>p>span.ng-binding"), "Fiber är beställd till adressen")) #Option 3 - text_to_be_present_in_element and XPATHelement = WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element((By.XPATH, "//div[@class='infoMessageInner']/p/span[@class='ng-binding']"), "Fiber är beställd till adressen")) #Option 4 - text_to_be_present_in_element_value and XPATHelement = WebDriverWait(driver, 20).until(EC.text_to_be_present_in_element_value((By.XPATH, "//div[@class='infoMessageInner']/p/span[@class='ng-binding']"), "Fiber är beställd till adressen"))
Text will be:
Fiber är beställd till adressen. Tjänsterna kan du beställa när installationen är färdig.
Solution 2:
If you have no more <span>
elements in html, you can just find first span element with driver.find_element_by_tag_name('span').text
Solution 3:
You can use below bindings in CSS selector
.ng-binding
Edit:
driver.find_element_by_css_selector('.ng-binding').text
Post a Comment for "How To Extract Data From The Following Html?"