在练习企业微信项目的时候,定位首页的添加成员控件,执行click操作,总是会点击到“打卡”控件,但是执行获取文本操作(element.text)的时候又能正常获取,代码如下:
from time import sleep
from selenium import webdriver
from selenium.webdriver.remote.webdriver import WebDriver
class BasePage:
_base_url = ""
def __init__(self, driver: WebDriver = None):
if driver is None:
chrome_opts = webdriver.ChromeOptions()
chrome_opts.debugger_address = "127.0.0.1:9222"
self.driver = webdriver.Chrome(options=chrome_opts)
self.driver.get(self._base_url)
sleep(3)
else:
self.driver = driver
self.driver.maximize_window()
self.driver.implicitly_wait(3)
def find(self, by, locator):
return self.driver.find_element(by, locator)
from selenium.webdriver.common.by import By
from pageobject.page.add_member import AddMember
from pageobject.page.base_page import BasePage
class IndexPage(BasePage):
_base_url = "https://work.weixin.qq.com/wework_admin/frame#index"
def goto_add_member(self):
self.find(By.CSS_SELECTOR, ".index_service_cnt.js_service_list a:nth-child(1)").click() # 这里执行click就会点击到“打卡”
# element=self.find(By.CSS_SELECTOR, ".index_service_cnt.js_service_list a:nth-child(1)")
# print(element.text) # 这里获取文本又没有问题
return AddMember(self.driver)
from pageobject.page.index import IndexPage
class TestIndex:
def setup(self):
self.index = IndexPage()
def teardown(self):
self.index.driver.quit()
def test_click_add_member(self):
self.index.goto_add_member()
from pageobject.page.base_page import BasePage
class AddMember(BasePage):
def save(self):
pass