TA的每日心情 | 无聊 昨天 09:47 |
---|
签到天数: 528 天 连续签到: 1 天 [LV.9]测试副司令
|
1测试积点
最近在学selenium,有幸能看到几位大能的代码,但是这些代码与我平常所见的格式大不相同,因此想请教一下写这类代码的时候的样板(主要是find_element那几行),望指点一二:(下边的代码所执行的目标都是一样的,只是写的人不同,格式不同)
1(这是我写的):
- from selenium import webdriver
- import time
- driver = webdriver.Chrome()
- driver.get('https://wenku.baidu.com/view/83a62ad5316c1eb91a37f111f18583d048640f3c')
- time.sleep(5)
- elements=driver.find_elements_by_class_name('read-all')
- element=elements[0]
- #print(element)
- element.click()
- yhm=driver.find_elements_by_css_selector('#TANGRAM__PSP_11__footerULoginBtn')
- print(yhm)
-
复制代码 2(大能A写的):
- from selenium.webdriver import Chrome
- from selenium.webdriver.common import by
- import time
- driver = Chrome()
- driver.get('https://wenku.baidu.com/view/83a62ad5316c1eb91a37f111f18583d048640f3c')
- time.sleep(2)
- element = driver.find_element(by.By.XPATH, '//span[@class="read-all"]')
- element.click()
- time.sleep(1)
- element_login = driver.find_element(by.By.XPATH, '//*[@id="TANGRAM__PSP_11__footerULoginBtn"]')
- print(element_login)
- time.sleep(2)
- element_login.click()
-
复制代码 3(大能B所写):
- WebElement el = driver.findElement(By.xpath("//div[@class='user-icon-content no-login user-icon-zhenxuan']"));
- Thread.sleep(1000);
- el.click();
- Thread.sleep(1000);
- el = driver.findElement(By.id("TANGRAM__PSP_11__footerULoginBtn"));
- Thread.sleep(1000);
- el.click();
-
复制代码
|
|