文件上传
文件上传 input标签直接使用sendkeys
from time import sleep
from selenium_webui.selenium_js.base import Base
# input框可以直接用sendkeys
class TestFile(Base):
def test_file(self):
self.driver.get('https://image.baidu.com/')
self.driver.find_element_by_xpath('//*[@id="sttb"]/img[1]').click()
self.driver.find_element_by_id('stfile').send_keys('D:\pyprojects\selenium_file_alert\单位logo.png')
sleep(5)
弹框处理
alert,confirm,prompt弹框
操作alert方法:
switch_to.alert() 切换到当前页面的alert弹框
text:返回alert/confirm/prompt中的文字信息
accept() 接受
dismiss() 拒绝
send_keys(keysToSend) 发送文本至弹框
from time import sleep
from selenium.webdriver import ActionChains
from selenium_webui.selenium_js.base import Base
class TestAlert(Base):
def test_alert(self):
self.driver.get('https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')
self.driver.switch_to.frame('iframeResult')
darg = self.driver.find_element_by_id('draggable')
drop = self.driver.find_element_by_id('droppable')
actions = ActionChains(self.driver)
actions.drag_and_drop(darg, drop).perform()
sleep(3)
self.driver.switch_to.alert.accept() # switch到这个弹框下 进行确认
self.driver.switch_to.default_content()
self.driver.find_element_by_id('submitBTN').click()
sleep(3)