簡體   English   中英

我如何使用python登錄

[英]How do I log in using python

我有這個代碼:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

path = r'C:\Users\test\Documents\Python Scripts\chromedriver.exe'

driver = webdriver.Chrome(path)

driver.get("http:\\www.wyzant.com")
link = driver.find_element_by_link_text("LOG IN")
link.click()

WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "username")))

username = driver.find_element_by_id("Username")
username.send_keys("test")

代碼沒有將“測試”發送到用戶名 ID。 我想一旦我能夠插入用戶名,我應該能夠弄清楚如何插入密碼並單擊登錄。

在javascript中我使用這個函數|

const button = await driver.wait(
      until.elementLocated(By.xpath('your xpath element')), 12000).then(button => {
      return driver.wait(until.elementIsVisible(button4),12000)},  function(button4) {
          if (button instanceof Error) {
            bot.sendMessage(-*****chatID,"Card info"+console.log(button)+"CRASH!⛔️");
              console.log(button, 'fail');
              console.log(Date(time));
              return WebDriver.quit();
          }
        })
      button.sendKeys('your text').then(async function() {
      console.log(button.sendKeys,'input info - done');
      return true//it existed
    })

這里有兩件事要改變。 元素 id 是Username username而不是username ,使用find_element_by_css_selector似乎有效。

所以,變化將如下

WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "Username")))

username = driver.find_element_by_css_selector(".sso-login-form > div:nth-child(2) > input:nth-child(2)")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM