driver.get(url)
을 호출하면 다른 함수로 작성하려고 할 때 오류가 발생합니다. 다음은 최소한의 기능적 방법입니다.Selenium의 driver.get()이 함수 합성에서 작동하지 않습니다.
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const R = require('ramda');
// Load a webpage
const loadPage = url => driver => driver.get(url)
// Find an WebElement via some locator
const getElement = locator => driver => driver.findElement(method)
// Locator by name
const byName = name => By.name(name)
// Send a series of input keys to a WebElement
const sendKeys = keys => elem => elem.sendKeys(keys)
다음 최소 예제는 Google을로드하고 검색 창에 메시지를 씁니다. 이 작품 :
// Navigate to the Google webpage
const loadGoogle = loadPage('http://google.com')
// Retrieve the search form element
const getSearchForm = getElement(byName('q'))
const driver = new webdriver.Builder().forBrowser('chrome').build();
loadGoogle(driver); // NOTE: I have to do this seperately -- cannot do it inside the composition
var app = R.compose(sendKeys('search input'), getSearchForm)
app(driver);
하지만 기능 성분 내에서 loadGoogle
을 포함 할 -이 깔끔한 것, 그리고 더 많은 '올바른'. 그래서 같이 :
var app = R.compose(sendKeys('search input'), getSearchForm, loadGoogle)
app(driver);
그러나 나는 driver.findElement is not a function
오류 얻을 :
/Users/name/Desktop/functional-test.js:9
const getElement = locator => driver => driver.findElement(locator)
^
TypeError: driver.findElement is not a function
at driver (/Users/name/Desktop/functional-test.js:9:48)
at /Users/name/node_modules/ramda/src/internal/_pipe.js:3:14
at /Users/name/node_modules/ramda/src/internal/_pipe.js:3:27
at /Users/name/node_modules/ramda/src/internal/_arity.js:5:45
at Object.<anonymous> (/Users/name/Desktop/functional-test.js:28:1)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
내가 loadPage
이 WebDriver 인스턴스를 반환하지 않기 때문에 그것의 가정을,하지만 확실 해요,하고 해결하는 방법을 모른다 그것.
'const loadPage = url => driver => driver.get (url)'을'const loadPage = url => driver = > {driver.get (url); 리턴 드라이버; }'그것이 당신을 위해 작동하는지 확인하십시오 –
아, 고쳐 주셨습니다! 고맙습니다. – user3668541