I'm trying to scrape some data using selenium. I can get the wanted page to load and open the subpage, but i cannot get the selenium driver to find the xpath from the submenu.
I have tried clicking the subpage with the selenium driver, but again i have a problem getting selenium to use the xpath.
path = r"C:\Program Files\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(path)
#opening website
driver.get("http://elpris.dk")
time.sleep(2)
#setting zipcode to 2200 Nørrebro
driver.find_element_by_xpath("""//*[@id="zip"]""").click()
driver.find_element_by_xpath("""//*[@id="zip"]""").send_keys("2200")
#selecting the dropdown menu
driver.find_element_by_xpath("""//*[@id="btnSelectProfile"]""").click()
#selecting hus 4000 kwh
driver.find_element_by_xpath("""//*[@id="home"]/div[1]/div/div/form/div/ul/li[4]/span/a""").click()
#clicking on "Find Priser"
driver.find_element_by_xpath("""//*[@id="btnSubmitSearch"]""").click()
time.sleep(2)
#scrolling down to get all the table rows to make sure the full product page is loaded
i = 0
while i < 50:
driver.find_element_by_xpath("""/html/body""").send_keys(Keys.END)
i += 1
time.sleep(2)
#counting number of rows
rows = len(driver.find_elements_by_xpath("""//*[@id="results"]/div[2]/div[2]/div/div[2]/div/div/table/tbody/tr"""))
#counting number of col
cols = len(driver.find_elements_by_xpath("""//*[@id="results"]/div[2]/div[2]/div/div[2]/div/div/table/tbody/tr[1]/td"""))
print (rows)
print (cols)
#scroll up
driver.find_element_by_xpath("""/html/body""").send_keys(Keys.HOME)
time.sleep(2)
#entering each indivudual row and getting info
driver.find_element_by_xpath("""//*[@id="results"]/div[2]/div[2]/div/div[2]/div/div/table/tbody/tr[1]//*[@id="btnSeeMore"]""").click()
time.sleep(2)
abonnement = driver.find_element_by_xpath("""/html/body/div[6]/div/div/div/accordion/div/div[2]/div[2]/div/div/div/div[1]/span[3]/div[1]/span[2]""").text()
print(abonnement)
i want to get text from the sub page and then close it and continue to open and grab info from all the subpages.
first off i just need to be able to get som info from the first menu. For example the text in the red circle
an example of this could be the name of the company providing the service.