我需要从下拉菜单中选择一个元素。

例如:

<select id="fruits01" class="select" name="fruits">
  <option value="0">Choose your fruits:</option>
  <option value="1">Banana</option>
  <option value="2">Mango</option>
</select>

1)首先我得点击它。我是这样做的:

inputElementFruits = driver.find_element_by_xpath("//select[id='fruits']").click()

2)之后,我必须选择好的元素,让我们说芒果。

我尝试用inputElementFruits.send_keys(…)来做,但它不起作用。

我想刮取无限滚动实现的页面的所有数据。下面的python代码可以工作。

for i in range(100):
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(5)

这意味着每当我向下滚动到底部时,我都需要等待5秒,这通常足以让页面完成加载新生成的内容。但是,这可能并不省时。页面可能在5秒内完成新内容的加载。如何在每次向下滚动时检测页面是否完成了新内容的加载?如果我能检测到这一点,一旦我知道页面完成加载,我就可以再次向下滚动以查看更多内容。这样更节省时间。

我试图用一个URL启动chrome浏览器,浏览器启动后,它什么也不做。

1分钟后我看到如下错误:

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

我的配置:

Chrome浏览器:66 ChromeBrowser: 2.39.56

又及,在Firefox中一切都很好

我正在寻找一种快速的方法来键入进入或返回键在硒。

不幸的是,我试图测试的表单(不是我自己的代码,所以我不能修改)没有Submit按钮。当手动使用它时,我只需输入Enter或Return。我怎么能做到这一点与硒类型命令,因为没有按钮点击?

我正在使用python和selenium,并从这个网站下载了用于我的windows计算机的chromedriver: http://chromedriver.storage.googleapis.com/index.html?path=2.15/

下载压缩文件后,我将压缩文件解压缩到我的下载文件夹中。然后我把可执行二进制文件(C:\Users\michael\Downloads\chromedriver_win32)的路径放到环境变量“path”中。

然而,当我运行以下代码:

  from selenium import webdriver

  driver = webdriver.Chrome()

... 我一直得到以下错误消息:

WebDriverException: Message: 'chromedriver' executable needs to be available in the path. Please look at     http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver

但是-如上所述-可执行文件在路径中(!)…这是怎么回事?

我试图用Selenium测试一个复杂的JavaScript接口(使用Python接口,并跨多个浏览器)。我有一些按钮的形式:

<div>My Button</div>

我希望能够搜索基于“我的按钮”(或非大小写敏感,部分匹配,如“我的按钮”或“按钮”)的按钮。

我发现这非常困难,以至于我觉得我错过了一些明显的东西。到目前为止,我所拥有的最好的东西是:

driver.find_elements_by_xpath('//div[contains(text(), "' + text + '")]')

但是,这是区分大小写的。我尝试的另一件事是遍历页面上的所有div,并检查元素。文本属性。然而,每次你得到这样的情况:

<div class="outer"><div class="inner">My Button</div></div>

div.outer也有“My Button”作为文本。为了解决这个问题,我尝试查看div.outer是否是div.inner的父元素,但我不知道如何做到这一点(element.get_element_by_xpath('..')返回元素的父元素,但它测试不等于div.outer)。

此外,遍历页面上的所有元素似乎真的很慢,至少使用Chrome web驱动程序是这样。

想法吗?


我在这里问了一个更具体的版本:如何在Selenium WebDriver中获取元素的文本,而不包括子元素文本?

我试图把可能的解决方案的浏览器自动测试套装和无头浏览器平台能够抓取。


浏览器测试/抓取:

Selenium——浏览器自动化的多语言旗舰,Python、Ruby、JavaScript、c#、Haskell等的绑定,用于Firefox的IDE(作为扩展),用于更快的测试部署。可以作为一个服务器,并有吨的功能。

JAVASCRIPT

PhantomJS - JavaScript, headless testing with screen capture and automation, uses Webkit. As of version 1.8 Selenium's WebDriver API is implemented, so you can use any WebDriver binding and tests will be compatible with Selenium SlimerJS - similar to PhantomJS, uses Gecko (Firefox) instead of WebKit CasperJS - JavaScript, build on both PhantomJS and SlimerJS, has extra features Ghost Driver - JavaScript implementation of the WebDriver Wire Protocol for PhantomJS. new PhantomCSS - CSS regression testing. A CasperJS module for automating visual regression testing with PhantomJS and Resemble.js. new WebdriverCSS - plugin for Webdriver.io for automating visual regression testing new PhantomFlow - Describe and visualize user flows through tests. An experimental approach to Web user interface testing. new trifleJS - ports the PhantomJS API to use the Internet Explorer engine. new CasperJS IDE (commercial)

node . js

Node-phantom - bridges the gap between PhantomJS and node.js WebDriverJs - Selenium WebDriver bindings for node.js by Selenium Team WD.js - node module for WebDriver/Selenium 2 yiewd - WD.js wrapper using latest Harmony generators! Get rid of the callback pyramid with yield ZombieJs - Insanely fast, headless full-stack testing using node.js NightwatchJs - Node JS based testing solution using Selenium Webdriver Chimera - Chimera: can do everything what phantomJS does, but in a full JS environment Dalek.js - Automated cross browser testing with JavaScript through Selenium Webdriver Webdriver.io - better implementation of WebDriver bindings with predefined 50+ actions Nightmare - Electron bridge with a high-level API. jsdom - Tailored towards web scraping. A very lightweight DOM implemented in Node.js, it supports pages with javascript. new Puppeteer - Node library which provides a high-level API to control Chrome or Chromium. Puppeteer runs headless by default.

网页抓取/挖掘

Scrapy - Python,主要是一个scraper/miner -快速,有良好的文档,可以与Django Dynamic scraper链接,用于良好的挖掘部署,或者Scrapy Cloud用于PaaS(无服务器)部署,可以在终端或服务器独立进程中工作,可以与芹菜一起使用,构建在Twisted之上 node.js模块,尚未测试。 Node-Crawler - node.js模块,尚未测试。

在线工具

新的网页抓取语言-简单的语法抓取网页 新的在线HTTP客户端-专用的SO回答 在线运行CasperJS脚本

Android自动化工具

新的Mechanica浏览器应用程序


相关链接及资源

网络抓取软件的比较 js:图像分析和比较

问题:

任何纯Node.js解决方案或Nodejs到PhanthomJS/CasperJS模块,实际上工作并有文档?

答:奇美拉似乎是朝那个方向发展的,结帐奇美拉

还有比Selenium更容易注入JavaScript的解决方案吗? 你知道什么纯红宝石的解决方案吗?

答:用基于ruby的解决方案签出rjk创建的列表

你知道相关的技术或解决方案吗?

请随意编辑这个问题并添加您希望的内容!感谢您的贡献!

我想找的是:

getElementByXpath(//html[1]/body[1]/div[1]).innerHTML

我需要得到元素的innerHTML使用JS(使用硒WebDriver/Java,因为WebDriver不能找到它本身),但如何?

我可以使用ID属性,但不是所有元素都有ID属性。

(固定)

我使用jsoup在Java中完成它。这符合我的需要。

我只在Chrome浏览器中看到这个。

完整的错误信息如下:

“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”

“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。

我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。