import os import time import platform from selenium import webdriver as webdriver1 from selenium.webdriver.ie.options import Options from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from config import global_wait,root_url,use_edge,iedriver_path,edgedriver_path,chromedriver_path from public.basiclogger import LOGGING class BaseCase(object): '''基础用例''' def get_web_driver(self,url,data=None,browser='ie'): if browser=='chrome': #if platform.system()=="Windows": # os.system(r'taskkill /f /im chrome.exe') #else: # os.system(r"ps aux |grep chrome|awk '{print $2}'|xargs -i kill {}") options = webdriver1.ChromeOptions() options.add_experimental_option('excludeSwitches', ['enable-logging']) self.driver = webdriver1.Chrome(executable_path=chromedriver_path,options=options) self.driver.get(url) self.driver.maximize_window() self.driver.implicitly_wait(global_wait) else: #启动IE之前先杀死电脑上所有的IE if use_edge: os.system(r'taskkill /f /im msedge.exe') else: os.system(r'taskkill /f /im iexplore.exe') if use_edge: file1=edgedriver_path else: file1=iedriver_path options = Options() options.ignore_protected_mode_settings = True options.ignore_zoom_level = True if use_edge: options.attach_to_edge_chrome = True options.edge_executable_path = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" else: options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"') self.driver=webdriver1.Ie(executable_path=file1,options=options) self.driver.get(url) self.driver.maximize_window() self.driver.implicitly_wait(global_wait) def get_logger(self): #创建日志文件名 filename=self.data["case_name"]+'_'+time.strftime("%Y-%m-%d_%H-%M-%S") #保存连接 filename1=os.path.join(r'test_log',filename+r'.log') LOGGING1=LOGGING(log_name=filename,log_dir="test_log") self.logger=LOGGING1.logObject self.LOGGER=LOGGING1
时间: 2024-02-17 17:01:41 浏览: 46
在您提供的代码中,第一行需要将多个导入语句分开,即:
```
import os
import time
import platform
from selenium import webdriver as webdriver1
from selenium.webdriver.ie.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from config import global_wait,root_url,use_edge,iedriver_path,edgedriver_path,chromedriver_path
from public.basiclogger import LOGGING
```
此外,我还注意到您的代码缩进存在问题,建议仔细检查缩进是否正确,以确保代码可以正确执行。
相关问题
from selenium import webdriver from selenium.webdriver.chrome.options import Options from openpyxl import load_workbook import time
您好!您提供的代码是使用 Selenium、Chrome WebDriver、Openpyxl 进行操作的示例代码。这段代码的功能是使用 Selenium 控制 Chrome 浏览器进行网页自动化操作,并使用 Openpyxl 进行 Excel 文件的读写操作。
如果您有任何关于这段代码的问题或需要进一步的帮助,请告诉我。
from selenium.webdriver.support.wait import WebDriverWait
`WebDriverWait`是Selenium中的一个类,用于等待特定条件出现后再进行下一步操作。在使用WebDriverWait时,我们需要指定等待的最长时间和等待条件,如果在等待时间内等待条件未满足,则会抛出一个TimeoutException异常。使用示例:
```
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "kw"))
)
element.send_keys("Selenium")
```
以上代码中,我们在打开百度页面后,使用WebDriverWait等待10秒钟,直到页面中id为“kw”的元素出现后,才进行输入操作。如果在10秒钟内元素未出现,则抛出TimeoutException异常。
相关推荐
![nupkg](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)