getAttribute 获取元素属性 单选框 radio 复选框 checkbox click clear (清除选中状态) isSelected 查看是否被选中 按钮button / 超链接 a click isEnabled 查看是否可以操作 复杂 组合键操作 一般使用click方法,如果是chrome浏览器,点击超链接 同时按ctrl会打开新标签,shift打开新的窗口。
from selenium import webdriver driver = webdriver.Chrome() driver.maximize_window() driver.get('http://') driver.implicitly_wait(8) for i in driver.find_elements_by_xpath("//*/input[@type='radio']"): i.click() 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 2、点击复选框 本文介绍...
driver.get("http://localhost:8080/click.html") button1 = driver.find_element(By.ID, "button1") is_displayed = button1.is_enabled() if is_displayed: button1.click() 2、Submit操作 演示案例: 点击(鼠标左键)页面按钮:submit() 示例代码如下: driver.get("http://localhost:8080/submit.html")...
from seleniumimportwebdriver driver=webdriver.Chrome()driver.maximize_window()driver.get('https://www.baidu.com')driver.implicitly_wait(8)driver.find_element_by_xpath("//*[@id='u1']/a[7]").click()time.sleep(1)driver.find_element_by_xpath(".//*[@id='TANGRAM__PSP_10__footerULoginBtn...
import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome() driver.get("your_url_here") # 等待单选按钮可点击 radio_button = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.ID, "radio_button_id")) ) radio_button.click...
= self.driver.find_elements_by_name('gender')#可以通过属性值来判断勾选哪个值forelingender:ifel.get_attribute('value') =='Male':el.click()print('男')sleep(2)#也可以直接勾选第二个标签元素gender[1].click()sleep(3)self.driver.quit()if__name__=='__main__':TestCase().test_radio(...
点击(鼠标左键)页面按钮:click() 示例代码如下: python driver.get("http://localhost:8080/click.html")button1 = driver.find_element(By.ID,"button1")is_displayed = button1.is_enabled()ifis_displayed:button1.click() 2、Submit操作 演示案例: ...
Playwright是个开源工具,微软出品,支持用Python、JavaScript等语言控制浏览器。它能驱动Chrome、Firefox、Safari这些主流浏览器,模拟点击、输入、页面跳转等用户操作。跟Selenium比起来,Playwright在跨浏览器兼容性、API设计和执行速度上都更有优势,尤其适合现代Web应用那种动态加载的场景。我挺喜欢Playwright的几点:一是...
$("a").click(function() { alert('this is a link'); }); }); </script> </head> <body> <a href="http://www.weilian.com">Selenium</a> </body> </html> 技术解释: 使用JQuery要在html页面中先引用JQuery库,<script src="C:\jquery-3.2.1.js" type="text/javascript"></script>,在...
close() """ 基本元素相关方法 """ def type(self, selector, text): """ Operation input box. Usage: driver.type("i,el","selenium") """ el = self._locate_element(selector) el.clear() el.send_keys(text) def click(self, selector): """ It can click any text / image can be ...