After clicking the selected country I want to get the number of "Total Confirmed" from the top of the website
Website: https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6
Below is the code i have written:
poland = driver.find_element_by_xpath("//h5//span[contains(text(),'Poland')]")
poland.click()
To extract the number "1,862" clicking on Poland is not mandatory, instead you need to induce WebDriverWait for either visibility_of_element_located()
or element_to_be_clickable()
and you can use the following xpath based Locator Strategy :
Using XPATH and ``:
driver.get('https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6') print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//h5//span[contains(text(),'Poland')]//preceding::span[2]/strong"))).text)
Console Output:
1,862
Using XPATH and ``:
driver.get('https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6') print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h5//span[contains(text(),'Poland')]//preceding::span[2]/strong"))).text)
Console Output:
1,862
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.