I am trying to get Fax number
but they gave me nothing these is page link https://www.barreaunantes.fr/annuaire-des-avocats/stephanie-dreux/
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
PATH="C:\Program Files (x86)\chromedriver.exe"
url='https://www.barreaunantes.fr/annuaire-des-avocats/stephanie-dreux/'
driver =webdriver.Chrome(PATH)
wait = WebDriverWait(driver, 20)
driver.get(url)
Fax = driver.find_element(By.XPATH, "//p//strong[contains(text(),'Fax : ')]").text
print(Fax)
CodePudding user response:
You're trying to locate strong
tag but you need a p
tag:
Fax = driver.find_element(By.XPATH, "//p[strong[contains(text(),'Fax : ')]]").text
print(Fax.strip('Fax : '))
CodePudding user response:
As mentioned by JaSON you need to locate the p
tag element.
Also you need to use a WebDriverWait
to wait for visibility of that element.
As following:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
PATH="C:\Program Files (x86)\chromedriver.exe"
url='https://www.barreaunantes.fr/annuaire-des-avocats/stephanie-dreux/'
driver =webdriver.Chrome(PATH)
wait = WebDriverWait(driver, 20)
driver.get(url)
fax = wait.until(EC.visibility_of_element_located((By.XPATH, "//p[strong[contains(text(),'Fax : ')]]"))).text
print(fax.strip('Fax : '))