多测师肖sir_高级金牌讲师ui自动化__selenium之实战练习table表定位(6.11)

多测师肖sir_高级金牌讲师ui自动化__selenium之实战练习table表定位(6.11)_第1张图片
定位源码:
案例1:
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.ui import Select
dr=webdriver.Chrome()
url=“file:///E:/dcs/two/selenium%EF%BC%888%EF%BC%89/html%E5%BC%B9%E6%A1%86/table.html”
dr.get(url)
sleep(2)
dr.maximize_window()
sleep(2)
dr.find_element_by_name(‘user’).send_keys(“admin”)

sleep(2)
dr.find_element_by_name(“passwd”).send_keys(‘123456’)
sleep(2)
dr.find_element_by_name(“conpasswd”).send_keys(“123456”)
dr.find_element_by_xpath("/html/body/form/table/tbody/tr[5]/td[2]/input[1]").click()
sleep(2)
#dr.find_element_by_css_selector("[value=‘html’]").click()
#dr.find_element_by_css_selector("[value=‘python’]").click()
#dr.find_element_by_css_selector("[value=‘linux’]").click()
#dr.find_element_by_css_selector("[value=‘rfs’]").click()
e=dr.find_elements_by_css_selector("[type=‘checkbox’]") #复选框的类型
for i in e:
i.click()
sleep(2)
m=dr.find_element_by_xpath("/html/body/form/table/tbody/tr[7]/td[2]/select")
Select(m).select_by_index(1)
sleep(2)
dr.find_element_by_css_selector(’[value=“提交”]’).click()

==========================================================
案例2:

from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
driver = webdriver.Chrome()
url = r’F:\flask_projects\dcs\ui_zidonghua\table.html’
driver.get(url)

driver.find_element_by_css_selector(’[value=“boy”]’).click()
a = driver.find_elements_by_css_selector(’[type=“checkbox”]’)
for i in a:
i.click()

s = driver.find_element_by_tag_name(‘select’)
Select(s).select_by_index(1)
Select(s).select_by_visible_text(‘清华大学’)
time.sleep(1)
driver.find_element_by_css_selector(’[type=“submit”]’).click()

================================
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.ui import Select

url=r"file:///D:/Users/Desktop/%E8%AF%BE%E4%BB%B6/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20%20html%E7%BB%83%E4%B9%A0%E9%A1%B5%E9%9D%A2/table.html"
driver=webdriver.Chrome()
driver.get(url)
driver.find_element_by_name(“user”).send_keys(“zqc”)
driver.implicitly_wait(5)
driver.find_element_by_name(“passwd”).send_keys(“123456”)
driver.implicitly_wait(5)
driver.find_element_by_name(“conpasswd”).send_keys(“123456”)
driver.implicitly_wait(5)
driver.find_element_by_css_selector("[value=‘boy’]").click()
driver.implicitly_wait(5)
driver.find_element_by_css_selector("[value=‘html’]").click()
driver.find_element_by_css_selector("[value=‘linux’]").click()
driver.find_element_by_css_selector("[value=‘rfs’]").click()
driver.implicitly_wait(5)
s=driver.find_element_by_tag_name(‘select’)
Select(s).select_by_index(1)
Select(s).select_by_visible_text(“清华大学”)
sleep(3)
driver.find_element_by_css_selector(’[value=“重置”]’).click()

你可能感兴趣的:(自动化测试专栏)