Issue
I'm using below code to test login to a website.The code opens a webpage and wait for an element to load and then logs in using the provided credentials. I have put some messages in the code for me to identify whether the code is running. However, it is not working.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
s = Service("/usr/local/bin/chromedriver")
url = "https://atf.domain.com/"
driver = webdriver.Chrome(options=options, service=s)
driver.get(url)
print(driver.title)
try:
# wait 10 seconds before looking for element
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "username"))
print("Page loaded!")
)
except TimeoutException:
print("Page not loaded!")
driver.find_element(By.ID, "username").send_keys("[email protected]")
driver.find_element(By.ID, "password").send_keys("password")
driver.find_element(By.ID, "signinButton").click()
try:
# wait 10 seconds before looking for element
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "compose-delivery-link"))
print("Compose delivery page loaded!")
)
except TimeoutException:
print("Compose delivery page not loaded!")
driver.find_element(By.ID, "compose-delivery-link").click()
driver.close()
I'm getting below error,
File "sft_login_test.py", line 24
print('Page loaded!')
^
SyntaxError: invalid syntax
I have no tried idea how to fix this. Any help is greatly appreciated.
Solution
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "username"))
)
print("Page loaded!")
I guess the print
call should be outside the .until
arguments.
Answered By - FLAK-ZOSO
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.