Skip to content Skip to sidebar Skip to footer

Get Certain Elements Of Html Using Selenium

The reason why I'm using selenium is, that I navigate to the URL filling out several forms, and getting to a page that gives me an overview over insurance prices that are calculate

Solution 1:

Try with :

basicprice = driver.find_elements_by_xpath('(.//div[@class="main-price"]')[1])

discountedprice = driver.find_elements_by_xpath('(.//div[@class="discount-price"]')[1]);

selvrisiko = driver.find_elements_by_xpath('(.//div[@class="deductible-price"]')[1]);

print(basicprice.get_attribute("value"))

print(discountedprice.get_attribute("value"))

print(selvrisiko.get_attribute("value")) print this all webelement and you will get the result.

Solution 2:

You can get all with simple css selectors:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#...

wait = WebDriverWait(driver, 10)
resultatside = driver.get("https://forsikringsguiden.dk/#!/bilforsikring/resultatside")
prices = get_car_insurance()
basic_price = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[basicprice]"))).get_attribute(
        "basicprice")
discounted_price = driver.find_element_by_css_selector("[discountedprice]").get_attribute("discountedprice")
selvrisiko = driver.find_element_by_css_selector("[selvrisiko]").get_attribute("selvrisiko")

print(basic_price, discounted_price, selvrisiko)

Your code have is completely should be revised. Code below does nothing:

wait = WebDriverWait(driver,10)
wait

In code below resultatside is None - nothing, driver.get return None:

resultatside = driver.get("https://forsikringsguiden.dk/#!/bilforsikring/resultatside")

Post a Comment for "Get Certain Elements Of Html Using Selenium"