自动化测试–浏览器
def control_chrome():
#启动浏览器
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option(“useAutomationExtension”, False) #处理权限弹窗
driver_path = os.getcwd() + r’/driver/chromedriver.exe’
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=chromeOptions)
url = “https://www.baidu.com/”
driver.get(url)
#操作窗口大小
driver.maximize_window()
#元素操作
submit_button = driver.find_element_by_id("su")
button_text = driver.find_element_by_id("su").get_attribute("value")
if button_text in "百度一下":
print("right,this is 百度")
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
print(driver.title)
#多元素操作
pwd_list=driver.find_elements_by_xpath("xpath")
for ele in pwd_list:
if "1st" == ele.text:
print("get o