标签:对象 rate The value 时间 visible runner ble driver
Q1:unknown error: call function result missing ‘value‘
A1:更新到Chrome相应的webdriver ,更新地址:http://npm.taobao.org/mirrors/chromedriver/
Q2:右键Run 不想以 unittest方式
A2:File>Settings>Tools>Python Integrated Tools>Default testrunner 改成 py.test,且文件名不命名为 test
Q3:获取当前年月日
A3:
import datetime
datetime.datetime.now().year
datetime.datetime.now().month
datetime.datetime.now().day
now = datetime.datetime.now()
strftime = now.strftime(%Y-%m-%d %H:%M:%S) # 格式化时间
Q4: td 下包含变量 tmh 的内容
A4: td[contains(., "‘ + tmh + ‘")]
Q5: 获取当前时间
A5:
import datetime
nowTime=datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S‘)#现在
Q6: 脚本中执行JS脚本
A6:browser.execute_script("$(‘#4af4e8bd45b1d2d30145b67b940b0049 td:nth-child(2)‘).click())")
Q7: 遍历结果
A7:
table_element = browser.find_element_by_id(‘gridTestItem‘)
# 定位到行
tr_elements = table_element.find_elements_by_tag_name(‘tr‘)
td_list = []
for td in tr_elements:
td_elements = td.find_elements_by_tag_name(‘td‘)
# 第 6 列,即结果输入列拼接在列表中
td_list.append(td_elements[5])
for jg in td_list:
# 定位到列的对应输入框
jg1 = jg.find_element_by_id(‘comboText5‘)
# 清空并填写结果值
jg1.clear()
jg1.send_keys(‘5‘)
jg1.send_keys(Keys.ENTER)
sleep(1)
Q8: 选择下拉框数据
A8:
from selenium.webdriver.support.select import Select
browser.find_element_by_xpath(‘//*[@id="tabOther"]‘).click()
testTubeBaby = browser.find_element_by_id(‘testTubeBaby‘)
# 根据 Select 对象的value 值选择病理类型
Select(testTubeBaby).select_by_value("1")
Select(testTubeBaby).select_by_visible_text(pathology_type) # 根据下拉框值选择
Q9: input中的Id是动态的如何定位?
A9:
# 通过 xpath 定位到动态的 input 元素,id="divTestMethod" 是确定的,然后下面的div是动态的
jyff = browser.find_element_by_xpath(‘//*[@id="divTestMethod"]/div/input‘)
Q10:iframe中只有src属性,并且是动态变化的,如何定位?
A10:
# 转到iframe的src包含 tmh 变量的frame中
browser.switch_to.frame(browser.find_element_by_xpath(‘//iframe[contains(@src,"‘ + tmh + ‘")]‘))
Q11:指定浏览器路径?
A11:
chromedriver = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver)
标签:对象 rate The value 时间 visible runner ble driver
原文地址:https://www.cnblogs.com/liuliu3/p/9772940.html