mirror of
https://github.com/vimagick/dockerfiles.git
synced 2024-12-23 01:39:27 +02:00
update
This commit is contained in:
parent
9109980de6
commit
7d81f4019b
@ -22,13 +22,19 @@ firefox:
|
||||
$ docker-compose up -d
|
||||
```
|
||||
|
||||
## Client
|
||||
|
||||
demo.py
|
||||
> Another way to start selenium server:
|
||||
|
||||
```
|
||||
#!/usr/bin/env python3
|
||||
$ npm install -g selenium-standalone
|
||||
$ selenium-standalone install
|
||||
$ selenium-standalone start
|
||||
```
|
||||
|
||||
## Client
|
||||
|
||||
baidu-search.py
|
||||
|
||||
```
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
|
||||
|
||||
@ -37,16 +43,50 @@ driver = webdriver.Remote(
|
||||
desired_capabilities=DesiredCapabilities.FIREFOX
|
||||
)
|
||||
|
||||
driver.get('https://github.com/SeleniumHQ/docker-selenium')
|
||||
driver.save_screenshot('before-click.png')
|
||||
driver.find_element_by_css_selector('.author>a').click()
|
||||
driver.save_screenshot('after-click.png')
|
||||
driver.get('http://www.baidu.com/')
|
||||
driver.find_element_by_id('kw').send_keys('webdriver')
|
||||
driver.find_element_by_id('su').click()
|
||||
driver.save_screenshot('baidu.png')
|
||||
driver.close()
|
||||
```
|
||||
|
||||
search-baidu.js
|
||||
|
||||
```
|
||||
var webdriver = require('selenium-webdriver'),
|
||||
By = require('selenium-webdriver').By,
|
||||
until = require('selenium-webdriver').until,
|
||||
fs = require('fs');
|
||||
|
||||
webdriver.WebDriver.prototype.saveScreenshot = function(filename) {
|
||||
return driver.takeScreenshot().then(function(data) {
|
||||
fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''), 'base64', function(err) {
|
||||
if(err) throw err;
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
var driver = new webdriver.Builder()
|
||||
.forBrowser('firefox')
|
||||
.usingServer('http://127.0.0.1:4444/wd/hub')
|
||||
.build();
|
||||
|
||||
driver.get('http://www.baidu.com/');
|
||||
driver.findElement(By.id('kw')).sendKeys('webdriver');
|
||||
driver.findElement(By.id('su')).click();
|
||||
driver.wait(until.titleIs('webdriver_百度搜索'), 1000);
|
||||
driver.saveScreenshot('baidu.png');
|
||||
driver.quit();
|
||||
```
|
||||
|
||||
```
|
||||
# PYTHON
|
||||
$ pip3 install selenium
|
||||
$ python3 demo.py
|
||||
$ ls *.png
|
||||
$ python3 baidu-search.py
|
||||
|
||||
# NODEJS
|
||||
$ npm install -g selenium-webdriver
|
||||
$ node search-baidu.js
|
||||
```
|
||||
|
||||
[1]: http://seleniumhq.org/
|
||||
|
Loading…
Reference in New Issue
Block a user