【Selenium文本框输入】学习一下自动化脚本有关文本框输入的问题
功能:实现自动回帖问题:可以定位到文本框“textarea”但是没法输入字符
代码如下:# -*- coding: utf-8 -*-
"""
Created on Thu Aug 13 09:33:59 2020
@author: W
"""
from selenium import webdriver
from time import sleep
#import re_test
driver = webdriver.Chrome()
#driver.get('http://baidu.com')
driver.get("https://fishc.com.cn/forum.php?mod=guide")
element=driver.find_element_by_class_name("xst")
element.click()
#this_question = driver.find_element_by_link_text('习近平关切“小米粒”里的“大民生”')
page_list = driver.window_handles
driver.switch_to.window(page_list[-1])
print (driver.title)
#driver.find_element_by_xpath('//*[@id="postmessage_4910248"]/div/div/p/a').click()
#print(driver.find_element_by_css_selector(".atips_close"))
#scroller = driver.find_element_by_xpath('/html/body/div/div/div/div/table/tbody/tr/td/div/div/div/table/tbody/tr/td/text()')
#tr_list = scroller.find_elements_by_tag_name('tr')
#print(len(tr_list))
this_question = driver.title
#print(re_test.get_relpy(this_question))
driver.find_element_by_xpath('//*[@id="ls_username"]').send_keys("username") #输入用户名
sleep(1)
driver.find_element_by_xpath('//*[@id="ls_password"]').send_keys("password") #输入密码
sleep(1)
driver.find_element_by_xpath('//*[@id="lsform"]/div/div/table/tbody/tr/td/button/em').click()
sleep(3)
driver.find_element_by_id('post_reply').click()
#iframe = driver.find_element_by_tag_name("iframe");
# 切换入iframe
#driver.switch_to.frame(iframe);
driver.find_element_by_name('message').click()
print(driver.find_element_by_name('message').tag_name) #打印tag name
driver.find_element_by_name('message').clear()
driver.find_element_by_name('message').send_keys("谢谢!")
#driver.switch_to.default_content()
sleep(10)
#driver.quit() 本帖最后由 suchocolate 于 2020-8-14 21:07 编辑
没点击发表回复
driver.find_element_by_name('replysubmit').click()
页:
[1]