How to use this.getPageSource method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

scrape_site.js

Source:scrape_site.js Github

copy

Full Screen

...62 });63};64ScrapeSite.prototype.scrapePostList = function(url) {65 var scrapeArticlePromiseLists = [], articles = [];66 return this.getPageSource(url).then(function($) {67 $('article.excerpt header h2 a').each(function(i, elem) {68 var url = $(elem).attr('href');69 var scrapeArticlePromise = this.scrapeArticle(url).then(function(article) {70 return this.saveArticle(article);71 }.bind(this));72 scrapeArticlePromiseLists.push(scrapeArticlePromise);73 }.bind(this));74 return webdriver.promise.all(scrapeArticlePromiseLists).then(function(resolved) {75 var childrenList = [];76 resolved.forEach(function(resolvedE) {77 childrenList = childrenList.concat(resolvedE);78 });79 return childrenList;80 });81 }.bind(this))82};83ScrapeSite.prototype.scrapeArticles = function(urls) {84 var scrapeArticlePromiseLists = [], articles = [];85 _.each(urls, function(url) {86 var scrapeArticlePromise = this.scrapeArticle(url).then(function(article) {87 return this.saveArticle(article);88 }.bind(this));89 scrapeArticlePromiseLists.push(scrapeArticlePromise);90 }.bind(this));91 return webdriver.promise.all(scrapeArticlePromiseLists).then(function(resolved) {92 var childrenList = [];93 resolved.forEach(function(resolvedE) {94 childrenList = childrenList.concat(resolvedE);95 });96 return childrenList;97 });98};99ScrapeSite.prototype.scrapeArticle = function(url) {100 var driver = this.driver;101 var common_reg = /\s*(提取密碼|提取密码|提取码|提取碼|提取|密碼|密码|百度|百度云|云盘|360云盘|360云|360yun|yun)[::]?\s*(<[^>]+>)?\s*([0-9a-zA-Z]{4,})\s*/;102 var o = {};103 o['url'] = url;104 return this.getPageSource(url).then(function($) {105 o['title'] = $('h1.article-title').text();106 o['html'] = $('article.article-content').html();107 o['content'] = $('article.article-content').text();108 o['category'] = $('header.article-header .meta .muted').first().text().trim();109 o['status'] = {110 scraped_at: Date.now(),111 download_status: 'UNDOWNLOAD'112 }113 var externaBaidupanlUrls = $('article.article-content a.external').filter(function(i1, elem) {114 var href = $(this).attr('href');115 return /^(http|https):\/\/pan.baidu.com/.test(href);116 });117 if (externaBaidupanlUrls.length) { //<a href=""> has baidupan href118 externaBaidupanlUrls.map(function(i2, elem) {...

Full Screen

Full Screen

wdio-compat-plugin.js

Source:wdio-compat-plugin.js Github

copy

Full Screen

...51 const element = await this.$(selector);52 return element.getCSSProperty(propertyName);53 });54 browser.addCommand('getSource', async function() {55 return this.getPageSource();56 });57 // In V4 dimension with choices width|height were valid, V5 getWindowSize ignores any function parameters.58 // Adding for backwards compatability.59 browser.addCommand('getViewportSize', async function(dimension = '') {60 if (dimension.toLowerCase() === 'width' || dimension.toLowerCase() === 'height') {61 return this.getWindowSize()[dimension];62 }63 return this.getWindowSize();64 });65 browser.addCommand('isExisting', async function(selector) {66 const element = await this.$(selector);67 return element.isExisting();68 });69 browser.addCommand('isVisible', async function(selector) {70 const element = await this.$(selector);71 return element.isDisplayed();72 });73 browser.addCommand('moveToObject', async function(selector, x = undefined, y = undefined) {74 const element = await this.$(selector);75 return element.moveTo(x, y);76 });77 browser.addCommand('reload', async function() {78 return this.reloadSession();79 });80 browser.addCommand('screenshot', async function() {81 return this.takeScreenshot();82 });83 browser.addCommand('scroll', async function() {84 return this.scrollIntoView();85 });86 browser.addCommand('setCookie', async function(cookieObj) {87 return this.setCookies(cookieObj);88 });89 browser.addCommand('setValue', async function(selector, value) {90 const element = await this.$(selector);91 return element.setValue(value);92 });93 /**94 * In v4 the param is an object, in v5 width and height is passed.95 * Keeping as an object for backwards compatability.96 *97 * REF: https://github.com/webdriverio-boneyard/v4/blob/master/lib/commands/setViewportSize.js98 */99 browser.addCommand('setViewportSize', async function(widthHeightObject) {100 const { width, height } = widthHeightObject;101 return this.setWindowSize(width, height);102 });103 /* Same as getSource. */104 browser.addCommand('source', async function() {105 return this.getPageSource();106 });107 browser.addCommand('switchTab', async function(windowHandle) {108 return this.switchToWindow(windowHandle);109 });110 browser.addCommand('title', async function() {111 return this.getTitle();112 });113 browser.addCommand('waitForExist', async function(selector, timeout, reverse = false) {114 const element = await this.$(selector);115 return element.waitForExist({ timeout, reverse });116 });117 browser.addCommand('windowHandles', async function() {118 return this.getWindowHandles();119 });...

Full Screen

Full Screen

service.js

Source:service.js Github

copy

Full Screen

...40 const element = await this.$(selector);41 return element.getCSSProperty(propertyName);42 });43 browser.addCommand('getSource', async function () {44 return this.getPageSource();45 });46 browser.addCommand('getText', async function (selector) {47 const element = await this.$(selector);48 return element.getText();49 });50 // In V4 dimension with choices width|height were valid, V5 getWindowSize ignores any function parameters.51 // Adding for backwards compatability.52 browser.addCommand('getViewportSize', async function (dimension = '') {53 if (dimension.toLowerCase() === 'width' || dimension.toLowerCase() === 'height') {54 return this.getWindowSize()[dimension];55 }56 return this.getWindowSize();57 });58 browser.addCommand('isExisting', async function (selector) {59 const element = await this.$(selector);60 return element.isExisting();61 });62 browser.addCommand('isVisible', async function (selector) {63 const element = await this.$(selector);64 return element.isDisplayed();65 });66 browser.addCommand('moveToObject', async function (selector, x = undefined, y = undefined) {67 const element = await this.$(selector);68 return element.moveTo(x, y);69 });70 browser.addCommand('reload', async function () {71 return this.reloadSession();72 });73 browser.addCommand('screenshot', async function () {74 return this.takeScreenshot();75 });76 browser.addCommand('scroll', async function () {77 return this.scrollIntoView();78 });79 browser.addCommand('setCookie', async function (cookieObj) {80 return this.setCookies(cookieObj);81 });82 browser.addCommand('setValue', async function (selector, value) {83 const element = await this.$(selector);84 return element.setValue(value);85 });86 /**87 * In v4 the param is an object, in v5 width and height is passed.88 * Keeping as an object for backwards compatability.89 *90 * REF: https://github.com/webdriverio-boneyard/v4/blob/master/lib/commands/setViewportSize.js91 */92 browser.addCommand('setViewportSize', async function (widthHeightObject) {93 const { width, height } = widthHeightObject;94 return this.setWindowSize(width, height);95 });96 /* Same as getSource. */97 browser.addCommand('source', async function () {98 return this.getPageSource();99 });100 browser.addCommand('switchTab', async function (windowHandle) {101 return this.switchToWindow(windowHandle);102 });103 browser.addCommand('title', async function () {104 return this.getTitle();105 });106 browser.addCommand('waitForVisible', async function (selector, ms, reverse = false) {107 const element = await this.$(selector);108 return element.waitForDisplayed(ms, reverse);109 });110 browser.addCommand('waitForExist', async function (selector, ms, reverse = false) {111 const element = await this.$(selector);112 return element.waitForExist(ms, reverse);...

Full Screen

Full Screen

homePage.js

Source:homePage.js Github

copy

Full Screen

1import React, { PropTypes } from 'react';2import { connect } from 'react-redux';3import UrlForm from './urlForm';4import TagSummary from './tagSummary';5import PrettyPrintPageSource from './prettyPrintPageSource';6import { bindActionCreators } from 'redux';7import * as GetPageSourceActions from '../../actions/getPageSourceAction';8import DisplayChart from './displayChart'9class HomePage extends React.Component {10 constructor(props) {11 super(props);12 this.state = {13 highlight: null,14 url: null15 };16 this.getPageSource = this.getPageSource.bind(this);17 this.updateURLstate = this.updateURLstate.bind(this);18 this.clearHighlight = this.clearHighlight.bind(this);19 this.setHighlightTag = this.setHighlightTag.bind(this);20 }21 // isNewTags(tags) {22 // if (Object.getOwnPropertyNames(tags).length > 0) {23 // let newTags = Object.getOwnPropertyNames(tags);24 // let stateTags = Object.getOwnPropertyNames(this.state.tags);25 //26 // // compare length27 // if (newTags.length != stateTags.length) {28 // return false;29 // }30 //31 // for (let i = 0; i < newTags.length; i++) {32 // let propName = newTags[i];33 //34 // // compare values of object35 // if (newTags[propName] !== stateTags[propName]) {36 // return false;37 // }38 // }39 // this.setState({40 // tags41 // });42 // return true;43 // }44 // }45 getPageSource(event) {46 event.preventDefault();47 this.props.actions.getPageSource(this.state.url);48 }49 updateURLstate(event) {50 const url = event.target.value;51 this.setState({52 url53 });54 }55 setHighlightTag(tag) {56 this.setState({57 highlight: tag58 });59 }60 clearHighlight() {61 this.setState({62 highlight: null63 });64 }65 highlightTag(pageSource, tag) {66 if (tag && pageSource) {67 // let re = new RegExp("<(\/)?" + tag + "(.*)?>", "g");68 // let re = new RegExp("\s*<(\/){0,1}" + tag + "[^>]*>", "g");69 let re = new RegExp("\s*<[^>]*" + tag + "[^>]*>[\s]*", "g");70 let matchingHTMLChunks = pageSource.match(re);71 let htmlChunks = pageSource.split(re);72 let pageSourceArray = [];73 let htmlChunkFlag = 0;74 let len = htmlChunks.length + matchingHTMLChunks.length;75 for (let i = 0; i < len; i++) {76 if (htmlChunkFlag) {77 pageSourceArray.push(matchingHTMLChunks.shift());78 htmlChunkFlag = 0;79 } else {80 pageSourceArray.push(htmlChunks.shift());81 htmlChunkFlag = 1;82 }83 }84 return pageSourceArray;85 } else if (pageSource && !tag) {86 return [pageSource];87 } else {88 return [];89 }90 }91 render() {92 // console.log(this.props.payload);93 // console.log(this.state);94 return (95 <div id="content-wrapper">96 <div id="search">97 <img id="logo"/>98 <UrlForm99 onSearch={ this.getPageSource }100 onChange={ this.updateURLstate }101 />102 </div>103 <div id="sourcerer-content">104 <div className="left-content ">105 <PrettyPrintPageSource106 badUrl={ this.props.payload.error }107 prettyPrintPageSource={ this.props.payload.prettySource }108 highlighter={ this.highlightTag }109 tag={ this.state.highlight }110 />111 </div>112 <div className="right-content">113 <div id="chart">114 <DisplayChart115 tags={ this.props.payload.tagData }116 />117 </div>118 <div id="tags">119 <TagSummary120 tags={ this.props.payload.tagData }121 setHighlightTag={ this.setHighlightTag }122 clearHighlight={ this.clearHighlight }123 />124 </div>125 </div>126 </div>127 </div>128 );129 }130}131HomePage.propTypes = {132 actions: PropTypes.object.isRequired,133 payload: PropTypes.object.isRequired134};135// ownProps is a reference to the components attached to this component. That is why it is called own props136// state is the state that is in our redux store137// state.pageSource refers to the pageSource within redux-store --> rootReducer --> pageSourceReducer138function mapStateToProps(state, ownProps) {139 return {140 payload: state.pageSource141 };142}143// determines what actions are available in the component144function mapDispatchToProps(dispatch) {145 return {146 actions: bindActionCreators(GetPageSourceActions, dispatch)147 };148}...

Full Screen

Full Screen

plugin.js

Source:plugin.js Github

copy

Full Screen

...40 const {platformName} = driver.caps;41 if (strategy.toLowerCase() !== 'xpath') {42 return await next();43 }44 const xml = await this.getPageSource(null, driver, null, true);45 let newSelector = transformQuery(selector, xml, multiple);46 // if the selector was not able to be transformed, that means no elements were found that47 // matched, so do the appropriate thing based on element vs elements48 if (newSelector === null) {49 log.warn(`Selector was not able to be translated to underlying XML. Either the requested ` +50 `element does not exist or there was an error in translation`);51 if (multiple) {52 return [];53 }54 throw new errors.NoSuchElementError();55 }56 if (platformName.toLowerCase() === 'ios') {57 // with the XCUITest driver, the <AppiumAUT> wrapper element is present in the source but is58 // not present in the source considered by WDA, so our index path based xpath queries will...

Full Screen

Full Screen

WebExtension.js

Source:WebExtension.js Github

copy

Full Screen

...44 return new Promise((resolve, reject) => {45 // eslint-disable-next-line no-undef46 this.getCurrentTab()47 .then(tab => {48 this.getPageSource(tab.id)49 .then(source => resolve(source))50 .catch(err => reject(err))51 })52 .catch(err => reject(err))53 })54 } ...

Full Screen

Full Screen

getSource.js

Source:getSource.js Github

copy

Full Screen

1'use strict';2module.exports = (browser) => {3 browser.addCommand('getSource', function() {4 return this.getPageSource();5 });...

Full Screen

Full Screen

source.js

Source:source.js Github

copy

Full Screen

1'use strict';2module.exports = (browser) => {3 browser.addCommand('source', function() {4 return this.getPageSource();5 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .getPageSource().then(function(source) {20 console.log('Page source: ' + source);21 })22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28 .remote(options)29 .init()30 .getSource().then(function(source) {31 console.log('Page source: ' + source);32 })33 .end();34var webdriverio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39 .remote(options)40 .init()41 .findElement('css selector', 'input[name="q"]').then(function(element) {42 console.log('Element found: ' + element);43 })44 .end();45var webdriverio = require('webdriverio');46var options = {47 desiredCapabilities: {48 }49};50 .remote(options)51 .init()52 .findElements('css selector', 'input[name="q"]').then(function(elements) {53 console.log('Elements found: ' + elements.length);54 })55 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var fs = require('fs');4var driver = new webdriver.Builder()5 .forBrowser('chrome')6 .build();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnG')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.getPageSource().then(function(source) {11 fs.writeFile("test.html", source, function(err) {12 if (err) {13 return console.log(err);14 }15 console.log("The file was saved!");16 });17});18driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.init({2}).then(function() {3 return driver.getPageSource();4}).then(function(source) {5 console.log(source);6}).done();7driver.init({8}).then(function() {9 return driver.getPageSource();10}).then(function(source) {11 console.log(source);12}).done();13Your name to display (optional):14Your name to display (optional):15driver.getPageSource().then(function(source) {16 console.log(source);17});18Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var source = this.getPageSource();2console.log(source);3var source = this.getPageSource();4console.log(source);5var source = this.getPageSource();6console.log(source);7var source = this.getPageSource();8console.log(source);9var source = this.getPageSource();10console.log(source);11var source = this.getPageSource();12console.log(source);13var source = this.getPageSource();14console.log(source);15var source = this.getPageSource();16console.log(source);17var source = this.getPageSource();18console.log(source);19var source = this.getPageSource();20console.log(source);21var source = this.getPageSource();22console.log(source);23var source = this.getPageSource();24console.log(source);25var source = this.getPageSource();26console.log(source);27var source = this.getPageSource();28console.log(source);29var source = this.getPageSource();30console.log(source);31var source = this.getPageSource();32console.log(source);33var source = this.getPageSource();34console.log(source);35var source = this.getPageSource();36console.log(source);37var source = this.getPageSource();38console.log(source);39var source = this.getPageSource();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful