第十期_Selenium 第二周_20190801

学习资料

表单

  • 用户名
  • 密码
  • 文件上传
  • 单选
  • 多选
  • Select

属性


        element=self.driver.find_element(By.CSS_SELECTOR, "#new_user > div.from-group.checkbox > label")
        logging.info(element.is_displayed())
        logging.info(element.id)
        logging.info(element.tag_name)
        logging.info(element.text)
        logging.info(element.location)
        logging.info(element.size)
        logging.info(element.rect)
        logging.info(element.get_attribute("for"))

INFO:root:True
INFO:root:e00ac286-eedc-4a2e-9235-48af3e3ea08d
INFO:root:label
INFO:root:记住登录状态(60 天)
INFO:root:{'x': 230, 'y': 235}
INFO:root:{'height': 20, 'width': 171}
INFO:root:{'height': 20, 'width': 171, 'x': 230, 'y': 235}
INFO:root:user_remember_me`

进入已经打开的浏览器进程

#windows
chrome.exe --remote-debugging-port=9222
#mac
/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome -remote-debugging-port=9222
#执行
/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9999
[46705:48391:0801/205950.195747:ERROR:token_service_table.cc(141)] Failed to decrypt token for service AccountId-100966385516644542985
[46705:48391:0801/205950.195818:ERROR:token_service_table.cc(141)] Failed to decrypt token for service AccountId-108225332417943636891

DevTools listening on ws://127.0.0.1:9999/devtools/browser/14613d27-a0b4-4392-8859-83c15edf0737
[46705:36871:0801/205951.773036:ERROR:gcm_store_impl.cc(930)] Failed to restore security token.
[46705:775:0801/205952.432869:ERROR:account_tracker.cc(240)] AccessTokenFetched error: Invalid credentials (credentials missing).
[46705:775:0801/205952.725691:ERROR:data_type_manager_impl.cc(38)] Passwords cryptographer error was encountered:
[46705:27139:0801/205957.434876:ERROR:mcs_client.cc(707)] Failed to log in to GCM, resetting connection.

连接调试开关打开的chrome

        options=webdriver.ChromeOptions()
        options.debugger_address="127.0.0.1:9222"

        self.driver=webdriver.Chrome(options)

文件上传

    def test_upload_file(self):
        element_add=self.driver.find_element(By.CSS_SELECTOR, ".js_upload_file_selector")
        element_add.click()
        self.driver.execute_script("arguments[0].click();", element_add)
        #
        # self.driver.execute_script("arguments[0].click();",
        #                            self.driver.find_element(By.CSS_SELECTOR, "#js_upload_input"))
        self.driver.find_element(By.CSS_SELECTOR, "#js_upload_input")\\
            .send_keys("/Users/seveniruby/PycharmProjects/Hogwarts10/images/霍格沃兹测试学院1024.png")

        print(self.driver.page_source)
        WebDriverWait(self.driver, 5).until(
            expected_conditions.invisibility_of_element_located((By.CSS_SELECTOR, ".js_uploadProgress_cancel"))
        )
        self.driver.execute_script("arguments[0].click();",
                                   self.driver.find_element_by_css_selector(".js_next"))



注入JS

        print(self.driver.execute_script("console.log('hello from selenium')"))
        print(self.driver.execute_script("return document.title;"))

        self.driver.execute_script("arguments[0].click();",
                                   self.driver.find_element_by_css_selector(".js_next"))

多浏览器管理

//todo

作业

  • 在企业微信里编写一个添加成员的用例,把代码贴到回复里