代码如下:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
class TestTestdemo():
def setup_method(self, method):
options = Options()
options.debugger_address = "127.0.0.1:9222"
self.driver = webdriver.Chrome(options=options)
def test_options(self):
self.driver.get("https://www.baidu.com/")
self.driver.find_element_by_css_selector(".index_service_cnt_itemWrap:nth-child(2) .index_service_cnt_item_title").click()
self.driver.find_element_by_css_selector(".ww_fileImporter_fileContainer_uploadInputMask").send_keys(r"C:\Users\Administrator\Desktop\project\xxxx.xlsx")
filename = self.driver.find_element_by_css_selector(".import_settingStage_upload_fileName util_fz_large").text
assert filename == "xxxx.xlsx"
如图,代码在 2 位置的页面寻找元素