1

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)

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

hey thanks for the help! im still looking as to how to use sample.html as a driver url instead of an actual url
0

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

3 Comments

oh sorry i meant to clarify that logging in meant the web site im testing not chrome itself
I know, if you use Selenium to load a profile as shown in the code, you won't have to re-login every time you try to visit the page.
do you know how to use a html file instead of a url with driver.get()?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.