This is a work-in-progress project where I enter a postcode (which will eventually become a list) into a website and then save the results from the website to a CSV using some kind of loop to move onto the next.
I’m having issues extracting the results from below
**Great news! You can connect to the CityFibre network**
Below is the code I’ve created so far, and I would love any pointers or improvements.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Firefox()
driver.get('https://cityfibre.com/')
assert 'CityFibre' in driver.title
time.sleep(2.5)
cookies = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "onetrust-accept-btn-handler")))
cookies.click()
PostCode = driver.find_element(By.XPATH,("//input[@class='w-full border rounded-lg border-grey-950 bg-white text-grey-950 ac-outline focus:border-cf-blue placeholder-grey-500 md:text-base lg:rounded-xl lg:rounded-tl-none lg:rounded-tl-none rounded-tl-none pr-32 pl-11 py-5']"));
PostCode.click()
PostCode.send_keys('EH17 7RY')
PostCode.send_keys(Keys.ENTER)
time.sleep(2.5)
PostCode.send_keys(Keys.TAB)
PostCode.send_keys(Keys.ENTER)
time.sleep(15)
message = driver.find_element(By.TAG_NAME,('h2')[0]).text
print(message)
print('The End')
2
Answers
Here is the refined code that also uses WebDriverWait
You have a typo in your code.
You are getting first element from selector
h2
that is actually illegal action.I think, you meant
Also, I suggest you to make locator more concrete and unique: