把以下代码转换成python3代码:# -- coding utf-8 --from selenium import webdriverfrom seleniumwebdrivercommonby import Byfrom seleniumwebdrivercommonkeys import Keysfrom seleniumwebdriversupportui import Selectfro
-- coding: utf-8 --
import time import unittest from selenium import webdriver from selenium.common.exceptions import NoSuchElementException, NoAlertPresentException from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select
class UntitledTestCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome(executable_path=r'') self.driver.implicitly_wait(30) self.base_url = "https://www.google.com/" self.verificationErrors = [] self.accept_next_alert = True
def test_untitled_test_case(self):
driver = self.driver
driver.get("https://aistudio.baidu.com/bj-cpu-01/user/2310718/4987598/lab/workspaces/auto-I/tree/main.ipynb")
driver.find_element(By.XPATH, "//input").click()
time.sleep(5)
driver.find_element(By.XPATH, "//div[@id='filebrowser']/div/div[3]/button").clear()
driver.find_element(By.XPATH, "//div[@id='filebrowser']/div/div[3]/button").send_keys(
"/Users/liyinhao/Documents/1679898897240.jpg")
def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
except NoSuchElementException as e:
return False
return True
def is_alert_present(self):
try:
self.driver.switch_to.alert
except NoAlertPresentException as e:
return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to.alert
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally:
self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if name == "main": unittest.main(
原文地址: https://www.cveoy.top/t/topic/efEI 著作权归作者所有。请勿转载和采集!