在Selenium中,我的ENV和Python代码是正确的,但在自动化过程中我遇到了一个错误

6l7fqoea  于 2024-01-05  发布在  Python
关注(0)|答案(1)|浏览(134)

我在练习自动化测试(Selenium with Python)登录Redhat Academy的网站。然而,在自动化过程中,我在终端中遇到错误。我相信我的代码和内部系统设置是正确的。(我已经在不同的网站上测试过了,比如Facebook,Riot,和一些虚拟的自动化实践网站).我附上两个截图-一个是我的代码,另一个是Redhat网站的inspect视图。* [* 只是想提一下,我还没有完全完成使用Python学习Selenium的过程,所以我可能会在编码过程中犯一些错误。]
x1c 0d1x的数据



我试图在红帽登录页面字段中写入名为“红帽登录或电子邮件”的内容。


xe55xuns

xe55xuns1#

告诉我这个是否有效。我换了几个零件。

  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.support import expected_conditions as EC
  5. driver = webdriver.Firefox()
  6. driver.maximize_window()
  7. driver.get("https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth?client_id=cloud-services&redirect_uri=https%3A%2F%2Fconsole.redhat.com%2F&state=e6a1436a-7cbc-4245-8289-cf84fe701743&response_mode=fragment&response_type=code&scope=openid&nonce=41932180-acf3-4b0a-928d-60bd3154bc6a") # I am assuming this is the correct starting page you can change as you want
  8. login_link = WebDriverWait(driver, 10).until(
  9. EC.element_to_be_clickable((By.XPATH, "//a[@href='https://console.redhat.com/' and @title='Log in']"))
  10. )
  11. login_link.click()
  12. username_field = WebDriverWait(driver, 10).until(
  13. EC.presence_of_element_located((By.XPATH, "//*[@id='username-verification']")) # Updated XPath
  14. )
  15. username_field.send_keys("HELLO") # Replace with your actual username
  16. # Assuming the form has an ID of "login-form"
  17. form = driver.find_element(By.ID, "login-form")
  18. form.submit()

字符串

展开查看全部

相关问题