from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 设置Edge浏览器选项 option = webdriver.EdgeOptions() option.add_experimental_option("detach", True) driver = webdriver.Edge(options=option) # 获取当前窗口大小 current_window_size = driver.get_window_size() # 获取屏幕大小 screen_size = driver.execute_script("return [window.screen.availWidth, window.screen.availHeight];") # 将浏览器窗口调整到与屏幕大小一致,模拟最大化效果 driver.set_window_size(screen_size[0], screen_size[1]) url = "http://localhost:8080/#/login" driver.get(url=url) import time time.sleep(5) input_user = driver.find_element(by=By.XPATH,value="//input[@type='text']") input_user.send_keys('syh') input_password = driver.find_element(by=By.XPATH,value="//input[@type='password']") input_password.send_keys('123456') time.sleep(3) login_button = driver.find_element(by=By.XPATH,value="//button[@type='button']") # 点击按钮 login_button.click() time.sleep(3) the_next_btn=driver.find_element(by=By.XPATH,value="//li[@id='jiben']") the_next_btn.click() time.sleep(3) add_btn=driver.find_element(by=By.XPATH,value="//button[@id='add']") add_btn.click() time.sleep(3) add_qiye = driver.find_element(by=By.XPATH,value="//input[@placeholder='请输入企业名称']") add_qiye.send_keys('syh公司') time.sleep(2) click_lei = driver.find_element(by=By.XPATH,value="//input[@placeholder='选择行业类型']") click_lei.click() time.sleep(1) click_lei_1 = driver.find_element(by=By.XPATH,value="//li[@class='el-select-dropdown__item'][1]") click_lei_1.click() time.sleep(1) add_address = driver.find_element(by=By.XPATH,value="//input[@placeholder='输入企业地址']") add_address.send_keys('河北省') time.sleep(2) add_submit = driver.find_element(by=By.XPATH,value="//button[@id='add_submit']") add_submit.click() time.sleep(1) time.sleep(5) # # 等待页面加载完成 # WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@class='search-input']"))) # # # 模拟搜索 # search_input = driver.find_element(By.XPATH, "//input[@class='search-input']") # search_button = driver.find_element(By.XPATH, "//button[@class='search-btn']") # search_button.click() # # # 等待视频列表加载完成 # video_list = WebDriverWait(driver, 10).until( # EC.presence_of_all_elements_located((By.XPATH, "//div[@class='aweme-list']//a")) # ) # # # 循环点击每一个视频播放 # for video in video_list: # video.click() # # # 等待视频加载播放一段时间 # time.sleep(5) # # # 切换到下一个视频,这里假设存在一个明显的“下一个”按钮,实际情况需要根据抖音网页版的实际DOM结构确定 # next_button = driver.find_element(By.XPATH, "//button[@class='next-video-button']") # if next_button.is_displayed(): # next_button.click() # else: # break # 退出浏览器 driver.quit()
python基于selenium实现自动处理登录。
标签:XPATH,18,button,指导,driver,element,寒假,input,find From: https://www.cnblogs.com/syhxx/p/17990560