Selenium with phantomJS fails but is working in Firefox -


i want automate download of google takeout data using selenium phantomjs webdriver. developed actions in selenium ide firefox add-on , converted html output of test case js using npm package selenium-html-js-converter. selectors working in mozilla firefox 45.0.2 if use converted version fails following message:

error: failure in selenium command "click("//tbody[@data-id=drive]/tr/td/div/", "")": [elementbyxpath("//tbody[@data-id=drive]/tr/td/div/")] error response status: 32, , invalidselector - argument invalid selector (e.g. xpath/css). 

this part want exclude google apps takeout. build selectors hand since don't want rely on classes , ids of elements since these automatically generated build tool , change @ time.

i read in post quotes problem evaluation still fails without quotes. tried change user agent in firefox 1 phantomjs using (mozilla/5.0 (unknown; linux x86_64) applewebkit/538.1 (khtml, gecko) phantomjs/2.1.1 safari/538.1) make sure site output same it's still working. don't know how change user agent string in selenium.

my selenium core code looks following (i omitted automatically generated helper functions keep tidy):

"use strict"; /* jslint node: true */  var assert = require('assert');  var browser, element, currentcommand = '',     options = {         timeout: 30000,         retries: 0,         screenshotfolder: 'screenshots/test_minimal_takeout_mobile_html',         baseurl: 'https://accounts.google.com/'     };  module.exports = function testminimaltakeoutmobilehtml(_browser, _options) {      browser = _browser;     var acceptnextalert = true;     getruntimeoptions(_options);     try {         currentcommand = 'open("/servicelogin?passive=1209600&continue=https%3a%2f%2faccounts.google.com%2fmanageaccount#identifier", "")';         browser.get(addbaseurl("/servicelogin?passive=1209600&continue=https%3a%2f%2faccounts.google.com%2fmanageaccount#identifier"));          currentcommand = 'type("id=email", "email@gmail.com")';         browser.elementbyid("email").clear();         browser.elementbyid("email").sendkeys("email@gmail.com");          currentcommand = 'click("id=next", "")';         browser.elementbyid("next").click();          currentcommand = 'uncheck("id=persistentcookie", "")';         if (browser.elementbyid("persistentcookie").isselected()) {             browser.elementbyid("persistentcookie").click();         };          currentcommand = 'type("id=passwd", "password")';         browser.elementbyid("passwd").clear();         browser.elementbyid("passwd").sendkeys("password");          currentcommand = 'clickandwait("id=signin", "")';         doandwait(function() {             browser.elementbyid("signin").click();         });          currentcommand = 'open("https://takeout.google.com/settings/takeout", "")';         browser.get(addbaseurl("https://takeout.google.com/settings/takeout"));          currentcommand = 'click("//tbody[@data-id=\'drive\']/tr/td/div/", "")';         //<<< fails here >>>         browser.elementbyxpath("//tbody[@data-id=\'drive\']/tr/td/div/").click();          currentcommand = 'click("//tbody[@data-id=\'chat\']/tr/td/div/", "")';         browser.elementbyxpath("//tbody[@data-id=\'chat\']/tr/td/div/").click();          currentcommand = 'click("//tbody[@data-id=\'gmail\']/tr/td/div/", "")';         browser.elementbyxpath("//tbody[@data-id=\'gmail\']/tr/td/div/").click();          currentcommand = 'click("//div[@data-state=\'1\']/div[2]/div[2]/div", "")';         browser.elementbyxpath("//div[@data-state=\'1\']/div[2]/div[2]/div").click();          currentcommand = 'mousedown("//div[@data-param=\'destination\']/div[2]/div[@role=\'presentation\']/div[2]", "")';         browser.elementbyxpath("//div[@data-param=\'destination\']/div[2]/div[@role=\'presentation\']/div[2]").mousedown();          currentcommand = 'mouseup("//div[@data-param=\'destination\']/div[2]/div[@role=\'presentation\']/div[2]", "")';         browser.elementbyxpath("//div[@data-param=\'destination\']/div[2]/div[@role=\'presentation\']/div[2]").mouseup();          currentcommand = 'click("//div[@data-param=\'destination\']/div[2]/div[3]/div[@data-value=\'drive\']", "")';         browser.elementbyxpath("//div[@data-param=\'destination\']/div[2]/div[3]/div[@data-value=\'drive\']").click();          currentcommand = 'click("//div[@data-state=\'2\']/div[2]/div[2]/div", "")';         browser.elementbyxpath("//div[@data-state=2]/div[2]/div[2]/div").click();      } catch (e) {         var failedscreenshot = options.screenshotfolder + '/exception@' + currentcommand.replace(/\(.+/, '') + '.png';         try {             createfolderpath(options.screenshotfolder);             browser.savescreenshot(failedscreenshot);         } catch (e) {             e.message = 'failure in selenium command "' + currentcommand + '": ' + e.message + ' (could not save screenshot after failure occured)';             throw e;         }         e.message = 'failure in selenium command "' + currentcommand + '": ' + e.message + ' (screenshot saved ' + failedscreenshot + ')';         throw e;     }  }; 

the screenshot taken when test fails shows me correct page.

i'm using latest stable releases of nodejs(5.10.1), phantomjs (2.1.1) , selenium (2.53.1).

what going wrong here?

you need quote each attribute value make xpath valide:

browser.elementbyxpath("//tbody[@data-id='drive']/tr/td/div/").click(); 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -