Reputation: 189
im testing a website but it requires me to log in each time, so ive saved the webpage i want to test into a html document.
im trying to open it by driver.get('file:///pp.html') but as of right now it just opens the file then closes, and none of the following code works:
rows = driver.find_elements_by_css_selector("table.aui tr") for row in rows: projectNames = row.find_elements_by_xpath(".//td[1]") for projectName in projectNames: print (projectName.text)
Upvotes: 1
Views: 582
Reputation: 12420
Simply put, look to load your chrome_profile or a duplicate of your browser profile (whatever browser you're using) to not have to re-login after the first time.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Path\\To\\chromedriver.exe", chrome_options=options)
https://www.youtube.com/watch?v=9UCaZT48Nnw
Upvotes: 0
Reputation: 1625
In order to give it some time in order to do things there are a few ways I would approach this.
one would be to set a time load page.
driver = set_page_load_timeout(10)
maybe I would also also use the time.sleep command from the time module
rows = driver.find_elements_by_css_selector("table.aui tr")
for row in rows:
time.sleep(2)
projectNames = row.find_elements_by_xpath(".//td[1]")
for projectName in projectNames:
time.sleep(1)
print (projectName.text)
time.sleep(1)
Lastly maybe if your driver is closing to quickly you should into the WebDriverWait() commmand. maybe something like this
from selenium.webdriver.support import expected_conditions as EC
row = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.xpath(".//td[1]"))
Hopefully this helps! good luck
Upvotes: 1