selenium常用元素定位方法
元素a
for link in driver.find_elements_by_xpath("//*[@href]"):
#print link.get_attribute('href')
s = '10072791.html'
if s in link.get_attribute('href'):
link.click()
break
for link in driver.find_elements_by_xpath("//*[@href]"):
#print link.get_attribute('href')
s = '10072791'
if s in link.get_attribute('href'):
print link.get_attribute('href')
driver.get(link.get_attribute('href'))
break
元素iframe
driver.switch_to.frame('home')
driver.switch_to.frame(reference)
driver.switch_to.parent_frame()
driver.switch_to.default_content()
iframe_name = driver.find_element_by_css_selector("iframe").get_attribute("name")
driver.switch_to.frame(iframe_name)
元素span
driver.find_element_by_xpath("//span[contains(text(),'增加')]").click()
selenium webDriver给隐藏域赋值 input hidden set value; selenium_webdriver(python)调用js脚本
js ="document.getElementById('opStatus').value='1'"
driver.execute_script(js)
#通过and连接更多的属性来唯一地标志一个元素 driver.find_element_by_xpath("//input[@class='nui-ipt-input' and @maxlength='256']").send_keys(u'自动化测试')