webdriver

Python Learning Day5

耗尽温柔 提交于 2020-03-24 10:30:25
Response响应 import requests response = requests.get('https://baidu.com') # response响应 print(response.status_code) # 获取响应状态码 print(response.url) # 获取url地址 print(response.encoding) # 字符编码 response.encoding = 'utf-8' print(response.text) # 获取文本 print(response.content) # 获取二进制流 print(response.headers) # 获取页面请求头信息 print(response.history) # 上一次跳转的地址 # 1、返回cookie字典 2、返回cookies对象 print(response.cookies) # 获取cookies信息, print(response.cookies.get_dict()) # 获取cookies信息转换成字典 print(response.cookies.items()) # 获取cookies信息转换成字典 print(response.encoding) print(response.elapsed) # 访问时间   import requests #

在Python中用Selenium执行JavaScript

狂风中的少年 提交于 2020-03-24 08:36:53
Selenium自己不带浏览器, 需要与第三方浏览器结合在一起使用.例如在Firefox上运行Selenium. PhantomJS是一个"无头"浏览器. 它会把网站加载到内存并执行页面上的JavaScript, 但是它不会向用户展示网页的图形界面. 把Selenium和PhantomJS结合在一起, 就可以运行一个非常强大的网络爬虫了, 可以处理cookie, JavaScript,header, 以及任何你需要做的事. Selenium可以从PyPI网站(https://pypi.python.org/simple/selenium)下载Selenium库, 也可以用pip安装. PhantomJS可以从官网下载(http://phantomjs.org/download.html) , PhantomJS不是一个Python库,不能用pip安装. 1 from selenium import webdriver 2 import time 3 4 driver = webdriver.PhantomJS(executable_path=' ') 5 driver.get("http://pythonscraping.com/pages/javascript/ajaxDemo.html") 6 time.sleep(3) 7 print(driver.find_element

selenium web中的下拉选项操作

佐手、 提交于 2020-03-23 15:57:41
from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium .webdriver.support.select import Selectfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byfrom selenium.common.exceptions import TimeoutException,NoSuchElementExceptiondriver = webdriver.Chrome()driver.get("https://baidu.com")wait=WebDriverWait(driver,10) #显示等待try: # 鼠标移动到设置按钮 setting_element=wait.until(EC.presence_of_element_located(( By.LINK_TEXT,"设置" ))) action_chains

How to launch all Karate features setting up which browser to use as an external maven variable

て烟熏妆下的殇ゞ 提交于 2020-03-23 11:59:20
问题 I was trying to find a way to launch all features in Karate testing through maven using an external variable to set up the browser (with a local webdriver or using a Selenium grid). So something like: mvn test -Dbrowser=chrome (or firefox, safari, etc) or using a Selenium grid: mvn test -Dbrowser=chrome (or firefox, safari, etc) -Dgrid="grid url" With Cucumber and Java this was quite simple using a singleton for setting up a global webdriver that was then used in all tests. In this way I

Null Pointer Exception Being returned - Java Selenium Webdriver

人盡茶涼 提交于 2020-03-23 07:30:19
问题 Getting Null Pointer exception when running test in Selenium WebDriver with Java. For some reason the test is retunrning null, even everything is being declared correctly (I think?). What am I missing/doing wrong here? //Given this code: public class HomePage extends DriverSetup{ @FindBy(className = "ico fa fa-lock") static WebElement loginButton; public HomePage (WebDriver driver){ super(driver); } public static void logInBut(){ loginButton.click(); }``` //When running this test: ```public

爬虫之selenium

你。 提交于 2020-03-23 03:21:24
selenium基本操作 概念:基于浏览器自动化的模块 appnium :基于手机自动化的模块的应用 环境的安装 pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple 跟爬虫之间的关联? 可以实现模拟登陆 便捷的捕获动态加载数据(可见即可得) 基本操作 导包: from selenium import webdriver (web浏览器,driver驱动) 必须提供对应浏览器的驱动程序(谷歌,火狐...) 谷歌浏览器驱动下载地址 实例化一个浏览器对象 bro = webdriver.Chrome(executable_path='./chromedriver.exe') # Chrome 谷歌浏览器 executable_path 浏览器驱动路径 标签定位 find系列的函数 标签对象.send_keys() :向指定标签中录入数据 提交标签.click() js 注入: 浏览器对象.execute_script("js代码") 浏览器对象.page_source :返回当前页面的页面源码数据,包含动态加载数据 关闭浏览器: 浏览器对象.quit() 缺点 爬取的效率比较低下 什么时候用selenium 动态加载的数据requests模块实在爬取不到,使用selenium 示例代码 登陆京东,搜索商品

How to fix unknown error: unhandled inspector error: “Cannot find context with specified id”

一曲冷凌霜 提交于 2020-03-23 02:07:56
问题 The following code throws occasionally an org.openqa.selenium.WebDriverException . WebElement element = driver.findElement(by); element.click(); (new WebDriverWait(driver, 4, 100)).until(ExpectedConditions.stalenessOf(element)); The page looks like this (by is a selector for <a></a> ) <iframe name="name"> <html id="frame"> <head> ... </head> <body class="frameA"> <table class="table"> <tbody> <tr> <td id="83"> <a></a> </td> </tr> </tbody> </table> </body> </html> </iframe> The message is

How to fix unknown error: unhandled inspector error: “Cannot find context with specified id”

无人久伴 提交于 2020-03-23 02:06:13
问题 The following code throws occasionally an org.openqa.selenium.WebDriverException . WebElement element = driver.findElement(by); element.click(); (new WebDriverWait(driver, 4, 100)).until(ExpectedConditions.stalenessOf(element)); The page looks like this (by is a selector for <a></a> ) <iframe name="name"> <html id="frame"> <head> ... </head> <body class="frameA"> <table class="table"> <tbody> <tr> <td id="83"> <a></a> </td> </tr> </tbody> </table> </body> </html> </iframe> The message is

Appium_iOS_Safari测试脚本(2)

╄→尐↘猪︶ㄣ 提交于 2020-03-22 13:16:42
经过多次调试,在Safari上的测试脚本终于可以运行了,不过部分元素还是无法识别,还需要继续调试; #!/usr/bin/env/python # -*-coding:utf-8-*- import pytest from time import sleep from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC class TestSafari: def setup(self): self.driver = webdriver.Safari() self.driver.get("https://www.xxxyyy.org") self.driver.maximize_window() # 最大化窗口 self.driver.implicitly_wait(10) # 隐式等待 def test_login_demo(self): try: login_click = """ setTimeout(function() { // 延迟 5

org.openqa.selenium.remote.ProtocolHandshake createSession INFORMATION: Attempting bi-dialect session with Selenium Grid

醉酒当歌 提交于 2020-03-22 09:29:31
问题 I set up a local selenium grid to test something. The build runs normal when connecting to another grid but when using the local grid the build just stops at this point: ------------------------------------------------------- T E S T S ------------------------------------------------------- Running xxx.xxxxxxxxxxxx.xxx.xxxxxxxxxxx.XXXXXXXXXXXX Sep 17, 2018 3:13:49 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFORMATION: Attempting bi-dialect session, assuming Postel's Law