webdriver

PhantomJS with Selenium: Message: 'phantomjs' executable needs to be in PATH

坚强是说给别人听的谎言 提交于 2020-01-30 06:36:13
问题 I having trouble installing PhantomJS to my project Following the suggestions from the similar question from so I defined the $PATH variable with executable path cd Users/zkid18/project/venv/venv_name/lib/python3.6/site-packages/phantomjs-2.1.1/bin export PATH=$PWD Then I try to create a driver with a virtual browser import from selenium import webdriver browser = webdriver.PhantomJS() On this step I got an error No such file or directory: 'phantomjs': 'phantomjs' What I am missing? 回答1: You

How to mouse hover a parent element and subsequently click on child element using Selenium and Action class

早过忘川 提交于 2020-01-30 05:17:52
问题 I wrote a test to hover mouse on an Element which has a link underneath it and to click the subElement. I keep getting NullPointerException. It had work previously and stopped working again. Actions mouseHover = new Actions(driver); mouseHover.moveToElement(ParentElement); mouseHover.moveToElement(subElement); mouseHover.click(subElement); 回答1: As per your code attempts you havn't invoked the perform() method for Mouse Hover . You need to induce WebDriverWait for the elements and can use the

拉钩爬虫

本小妞迷上赌 提交于 2020-01-29 22:34:41
#!/usr/bin/env python# -*- coding:utf-8 -*-import jsonimport reimport timeimport lxml.htmlfrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom redis_cache import RedisCacheclass LagouSpider(object): def __init__(self): # 调用webdriver.Chrome()启动浏览器 self.driver = webdriver.Chrome() self.url = 'https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=' self.detail_url = None def run(self): # 获得url打开浏览器 self.driver.get(self.url) while

Selenium WebDriver的使用(一)

我怕爱的太早我们不能终老 提交于 2020-01-29 21:13:29
Selenium WebDriver的相关介绍及资源下载:http://docs.seleniumhq.org/ 在2016年2月份Selenium WebDriver更新到了2.52.0版本,建议在使用旧版本的更新至该版本,在稳定性和性能上提高不少。 Selenium支持驱动众多的浏览器,包括PC、移动端及PhantomJS等。 以在windows下的JAVA开发环境为例,下载http://selenium-release.storage.googleapis.com/2.52/selenium-java-2.52.0.zip,解压后添加到工程中。PC端建议使用Google Chrome和PhantomJS。PhantomJS可以理解为没有界面的Safari(QtWebkit作为渲染引擎,JS引擎是JavascriptCore)。要使Selenium能驱动Google Chrome,还需要根据你的系统环境下载chromedriver,下载地址:https://sites.google.com/a/chromium.org/chromedriver/downloads。在本文撰写的时候,chromedriver最新版本为2.21。需要注意的是,2.21版本支持Chrome的版本为v46-50,如果chromedriver和你使用的Chome版本不匹配,程序可能无法正常工作。

解决:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' execu

假如想象 提交于 2020-01-29 05:36:05
# http://chromedriver.storage.googleapis.com/index.html 在准备写个脚本去爬取网易云歌曲信息时。用selenium去戳。这里采用的是chrome浏览器,链接网页时报错:File “C:\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py”, line 73, in init self.service.start() File “C:\Python37\lib\site-packages\selenium\webdriver\common\service.py”, line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home 解决办法: 安装与浏览器版本匹配的webdriver 1、打开谷歌浏览器, 在地址栏输入 chrome:/

【python-selenium】python-selenium安装配置

半腔热情 提交于 2020-01-29 00:16:13
selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: * 免费,也不用再为破解QTP而大伤脑筋 * 小巧,对于不同的语言它只是一个包而已,而QTP需要下载安装1个多G 的程序。 * 这也是最重要的一点,不管你以前更熟悉C、 java、ruby、python、或都是C# ,你都可以通过selenium完成自动化测试,而QTP只支持VBS * 支持多平台:windows、linux、MAC ,支持多浏览器:ie、ff、safari、opera、chrome * 支持分布式测试用例的执行,可以把测试用例分布到不同的测试机器的执行,相当于分发机的功能。 关于selenium的基础知识与java平台的结合,我之前写过一个《菜鸟学习自动化测试》系列,最近学python,所以想尝试一下selenium的在python平台如何搭建;还好这方法的文章很容易,在此将搭建步骤整理分享。 搭建平台windows 准备工具如下: ------------------------------------------------------------- 下载python https://www.python.org/ ----------------------------------------------------------

How does dot(.) in xpath to take multiple form in identifying an element and matching a text

徘徊边缘 提交于 2020-01-28 12:35:03
问题 I have the below dom structure: <h3 class="popover-title"> <div class="popup-title"> <div class="title-txt">Associated Elements &nbsp(5)</div> </div> </h3> I am trying to write an xpath which will identify the title "Associated Elements" under h3 tag. When my xpath is //div[contains(@class, popover)]//h3[contains(.,'Associated Elements')] the element is identified. However when my xpath is //div[contains(@class, popover)]//h3[contains(text(),'Associated Elements')] the element is not

How does dot(.) in xpath to take multiple form in identifying an element and matching a text

懵懂的女人 提交于 2020-01-28 12:31:51
问题 I have the below dom structure: <h3 class="popover-title"> <div class="popup-title"> <div class="title-txt">Associated Elements &nbsp(5)</div> </div> </h3> I am trying to write an xpath which will identify the title "Associated Elements" under h3 tag. When my xpath is //div[contains(@class, popover)]//h3[contains(.,'Associated Elements')] the element is identified. However when my xpath is //div[contains(@class, popover)]//h3[contains(text(),'Associated Elements')] the element is not

Selenium - Python webdriver path error system can't find the path specified

佐手、 提交于 2020-01-28 11:15:41
问题 Please help, whats wrong with the FF profile. I want to save a file from the website using Firefox and python webdriver from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.select import Select import os """from bs4 import BeautifulSoup""" fp = webdriver.FirefoxProfile() fp

python爬虫 --多线程【晋级版】--阻塞--队列--公共缓冲区

混江龙づ霸主 提交于 2020-01-28 08:11:50
阻塞 import time from selenium import webdriver from selenium . webdriver . support . wait import WebDriverWait from selenium . webdriver . support import expected_conditions as EC from selenium . webdriver . common . by import By import os import threading from queue import Queue class Tencent ( threading . Thread ) : def __init__ ( self , q , name ) : super ( ) . __init__ ( ) self . q = q self . name = name # self.page = page def save_to_html ( self , html_str , filename ) : dirname = os . path . dirname ( filename ) if not os . path . exists ( dirname ) : os . mkdir ( dirname ) with open (