from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import Select from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from time import sleep import datetime
#点击buchen按钮 defclickbucheng(driver): inputs = driver.find_elements_by_tag_name('input') for input in inputs: if input.get_attribute('value') == 'buchen': ActionChains(driver).click(input).perform() # writetohtml(driver,r"C:\Users\97532\OneDrive\程序仓库\getPlatzinBibliothek\1.html") window = driver.window_handles[1] driver.switch_to.window(window) driver.find_elements_by_css_selector('#bs_form_main > div > div.bs_etvg > div > label > div.bs_form_uni.bs_right.padding0 > input')[0].click() print(datetime.datetime.now().strftime('%Y.%m.%d-%H:%M:%S'),": start buchen") return1 return0
#发送表格信息 defsendform(driver): # writetohtml(driver,r'C:\Users\97532\OneDrive\程序仓库\getPlatzinBibliothek\2.html') #sex:M/W urinfo = {"sex":"M","vorname":"***","name":"***","strasse":"Hai***1","ort":"***","status":"S-RWTH","matnr":"***93","email":"im@xieqifei.com","telefon":"0049***4845"} radios = driver.find_elements_by_name('sex') vorname = driver.find_element_by_name('vorname') name = driver.find_element_by_name('name') strasse = driver.find_element_by_name('strasse') ort = driver.find_element_by_name('ort') status = Select(driver.find_element_by_name('statusorig')) matnr = driver.find_element_by_name('matnr') email = driver.find_element_by_name('email') telefon = driver.find_element_by_name('telefon') tnbed = driver.find_element_by_name('tnbed') submit = driver.find_element_by_css_selector('#bs_foot > div.bs_form_row > div.bs_right > input') for radio in radios: if radio.get_attribute("value") == urinfo['sex']: radio.click() break vorname.send_keys(urinfo['vorname']) name.send_keys(urinfo['name']) strasse.send_keys(urinfo['strasse']) ort.send_keys(urinfo['ort']) status.select_by_value(urinfo['status']) matnr.send_keys(urinfo['matnr']) email.send_keys(urinfo['email']) telefon.send_keys(urinfo['telefon']) tnbed.click() telefon.click() sleep(4) # WebDriverWait(driver, 10).until(EC.element_to_be_clickable(By.XPATH,'//*[@id="bs_foot"]/div[3]/div[2]/input')) submit.click() print(datetime.datetime.now().strftime('%Y.%m.%d-%H:%M:%S'),": send MsgForm") return1