【问题标题】:Prompt asking for user input before starting selenium and storing the input for later use, in python [duplicate]在 python 中提示在启动 selenium 之前询问用户输入并存储输入以供以后使用 [重复]
【发布时间】:2020-01-29 20:40:31
【问题描述】:

我有一个非常不整洁和初学者之类的脚本来自动化一些网页浏览。

但是在整个事情运行之前,我想先提示一个提示,要求用户输入一些输入并将该输入存储到不同的变量中,我可以稍后调用 selenium 以便稍后在浏览的某个阶段使用 -当我需要输入消息时。

我应该如何处理这个?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import ActionChains




driver = webdriver.Chrome()
driver.maximize_window()
driver.get("website")

driver.find_element_by_id("email").send_keys("email address")
driver.find_element_by_id("password").send_keys("pass123")
driver.find_element_by_id("submit").click()

driver.get("website")
driver.implicitly_wait(30)
driver.find_element_by_id("ui-id-6").click()


day = driver.find_element_by_xpath("/html/body/main/div[2]/div[6]/div[3]/div[4]/div/div[2]/table/tbody/tr[2]/td[2]")
ActionChains(driver).move_to_element(day).click().perform()

driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[4]/div/div[2]/table/tbody/tr/td/ul/li[1]/h3/a[3]').click()
driver.implicitly_wait(30)


driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[4]/i').click()
driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[3]/i').click()
driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[2]/i').click()
driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[1]/i').click()

【问题讨论】:

    标签: python html selenium user-input


    【解决方案1】:

    您可以像处理任何其他 python 输入变量一样处理它,因为您使用的是 selenium,所以没有什么不同。

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver import ActionChains
    
    
    print("Enter data here")
    variable = input()
    
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("website")
    
    driver.find_element_by_id("email").send_keys("email address")
    driver.find_element_by_id("password").send_keys("pass123")
    driver.find_element_by_id("submit").click()
    
    driver.get("website")
    driver.implicitly_wait(30)
    driver.find_element_by_id("ui-id-6").click()
    
    
    day = driver.find_element_by_xpath("/html/body/main/div[2]/div[6]/div[3]/div[4]/div/div[2]/table/tbody/tr[2]/td[2]")
    ActionChains(driver).move_to_element(day).click().perform()
    
    driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[4]/div/div[2]/table/tbody/tr/td/ul/li[1]/h3/a[3]').click()
    driver.implicitly_wait(30)
    
    
    driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[4]/i').click()
    driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[3]/i').click()
    driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[2]/i').click()
    driver.find_element_by_xpath('/html/body/main/div[2]/div[6]/div[3]/div[2]/form/div[3]/ul[1]/li[1]/i').click()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      • 2020-04-07
      • 2012-10-13
      相关资源
      最近更新 更多