量角器

时间:2016-11-24 12:18:15

标签: selenium protractor ng-file-upload gulp-protractor protractor-net

我有一个上传图像的模式。当我点击上传图片时,它会导航到本地计算机,然后选择指定的图像。 导航到本地计算机后出错。

错误:

  

消息:       失败:未知错误:元素在点(736,187)处无法点击。其他元素会收到点击:...         (会话信息:chrome = 54.0.2840.99)         (驱动程序信息:chromedriver = 2.25.426923(0390b88869384d6eb0d5d09729679f934aab9eed),platform = Windows NT   10.0.14393 x86_64)堆栈:       WebDriverError:未知错误:元素在点(736,187)处无法点击。其他元素会收到点击:...         (会话信息:chrome = 54.0.2840.99)         (驱动程序信息:chromedriver = 2.25.426923(0390b88869384d6eb0d5d09729679f934aab9eed),platform = Windows NT   10.0.14393 x86_64)           在WebDriverError(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ error.js:27:5)           at Object.checkLegacyResponse(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ error.js:639:15)           at parseHttpResponse(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ http \ index.js:538:13)           at client_.send.then.response(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ http \ index.js:472:11)           在ManagedPromise.invokeCallback_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:1379:14)           在TaskQueue.execute_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2913:14)           在TaskQueue.executeNext_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2896:21)           在asyncRun(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2820:25)           在C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:639:7           at process._tickCallback(internal / process / next_tick.js:103:7)       来自:任务:WebElement.click()           在Driver.schedule(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver.js:377:17)           at WebElement.schedule_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver.js:1744:25)           在WebElement.click(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver.js:1845:17)           at actionFn(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ built \ element.js:99:44)           在Array.map(本机)           在C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ built \ element.js:406:46           在ManagedPromise.invokeCallback_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:1379:14)           在TaskQueue.execute_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2913:14)           在TaskQueue.executeNext_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2896:21)           在asyncRun(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2775:27)错误           在ElementArrayFinder.applyAction_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ built \ element.js:403:27)           在ElementArrayFinder._this。(匿名函数)[点击](C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ built \ element.js:101:30)           在ElementFinder。(匿名函数)[点击](C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ built \ element.js:740:22)           在对象。 (C:\用户\ Telekha \应用程序数据\漫游\ NPM \ node_modules \量角器\示例\ loginpost.js:40:51)           在C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasminewd2 \ index.js:94:23           在新的ManagedPromise(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:1082:7)           在controlFlowExecute(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasminewd2 \ index.js:80:18)           在TaskQueue.execute_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2913:14)           在TaskQueue.executeNext_(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2896:21)           在asyncRun(C:\ Users \ Telekha \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2820:25)       发件人:任务:在控制流程中运行它("在仪表板上")           在对象。 (C:\用户\ Telekha \应用程序数据\漫游\ NPM \ node_modules \量角器\ node_modules \ jasminewd2 \ index.js:79:14)       从异步测试:       错误           在套房。 (C:\用户\ Telekha \应用程序数据\漫游\ NPM \ node_modules \量角器\示例\ loginpost.js:16:2)           在对象。 (C:\用户\ Telekha \应用程序数据\漫游\ NPM \ node_modules \量角器\示例\ loginpost.js:1:1)           在Module._compile(module.js:570:32)           在Object.Module._extensions..js(module.js:579:10)           在Module.load(module.js:487:32)           在tryModuleLoad(module.js:446:12)

     

2个规格,1个失败。

和我上传图片的代码:

element( by.css('[ng-click="imagePost()"]') ).click();   
browser.sleep(3000);
element(by.model("files")).click();
var path = require('path'); var fileToUpload = 'Desktop:/mdkg.jpg';
var absolutePath = path.resolve(fileToUpload); 
var button = element(by.css('[ngf-select]')); 
button.click(); 
var input = element(by.css('input[type="file"]'));     
input.sendKeys(absolutePath);
element(by.buttonText('Post Image')).click();

2 个答案:

答案 0 :(得分:0)

您可以使用wait元素进行点击

 var EC = protractor.ExpectedConditions;
 var element = element(by.xpath([xpath_locator]));
browser.wait(EC.elementToBeClickable(element(by.xpath([xpath_locator]))), 30000).then(function () {
                element.click();
});

在这种情况下,您可以通过任何定位器选择元素,我可以通过xpath选择它,

答案 1 :(得分:0)

包括以下语句:

browser.driver.manage().window().maximize();

onPrepare()文件的

protractor.conf.js方法,如下所示。

onPrepare () {
 browser.driver.manage().window().maximize();
}