Support frame number in withFrame().
Showing
1 changed file
with
9 additions
and
5 deletions
... | @@ -1870,18 +1870,22 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on | ... | @@ -1870,18 +1870,22 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on |
1870 | * Makes the provided frame page as the currently active one. Note that the | 1870 | * Makes the provided frame page as the currently active one. Note that the |
1871 | * active page will be reverted when finished. | 1871 | * active page will be reverted when finished. |
1872 | * | 1872 | * |
1873 | * @param String frameName Target frame name | 1873 | * @param String|Number frameNameOrNumber Target frame name or number |
1874 | * @param Function then Next step function | 1874 | * @param Function then Next step function |
1875 | * @return Casper | 1875 | * @return Casper |
1876 | */ | 1876 | */ |
1877 | Casper.prototype.withFrame = function withFrame(frameName, then) { | 1877 | Casper.prototype.withFrame = function withFrame(frameNameOrNumber, then) { |
1878 | "use strict"; | 1878 | "use strict"; |
1879 | this.then(function _step() { | 1879 | this.then(function _step() { |
1880 | if (this.page.childFramesName().indexOf(frameName) === -1) { | 1880 | if (utils.isNumber(frameNameOrNumber)) { |
1881 | throw new CasperError(f('No frame named "%s" was found.', frameName)); | 1881 | if (frameNameOrNumber > this.page.childFramesCount() - 1) { |
1882 | throw new CasperError(f('Frame number "%d" is out of bounds.', frameNameOrNumber)); | ||
1883 | } | ||
1884 | } else if (this.page.childFramesName().indexOf(frameNameOrNumber) === -1) { | ||
1885 | throw new CasperError(f('No frame named "%s" was found.', frameNameOrNumber)); | ||
1882 | } | 1886 | } |
1883 | // make the frame page the currently active one | 1887 | // make the frame page the currently active one |
1884 | this.page.switchToChildFrame(frameName); | 1888 | this.page.switchToChildFrame(frameNameOrNumber); |
1885 | }); | 1889 | }); |
1886 | try { | 1890 | try { |
1887 | this.then(then); | 1891 | this.then(then); | ... | ... |
-
Please register or sign in to post a comment