I.click(text, context) not working with Puppeteer
See original GitHub issueWhat are you trying to achieve?
I want to click a button in a test using I.click(buttonText, ‘button’)
What do you get instead?
> node_modules\\.bin\\codeceptjs run --grep "Handytarife"
CodeceptJS v1.2.1
Using test root "C:\Users\stefan.huber\projects\e2e-dashboard-client\examples\codeceptjs"
Search for Handytarife --
× When I search for "Handytarife" without specifying any details Then I will get a list of various tariffs in 3533ms
-- FAILURES:
1) Search for Handytarife
When I search for "Handytarife" without specifying any details Then I will get a list of various tariffs:
Clickable element jetzt vergleichen was not found inside element button
Scenario Steps:
- I.click("jetzt vergleichen", "button") at Test.Scenario (features\search-products_test.js:25:7)
- I.refreshPage() at Test.Scenario (features\search-products_test.js:20:13)
- I.setCookie({"domain":".check24.de","httpOnly":false,"name":"c24cb","path":"/","secure":false,"value":"1"}) at Test.Sc
enario (features\search-products_test.js:19:13)
- I.amOnPage("https://www.check24.de/handytarife") at Test.Scenario (features\search-products_test.js:9:7)
Run with --verbose flag to see NodeJS stacktrace
FAIL | 0 passed, 1 failed // 4s
Provide test source code if related
const assert = require('assert')
Feature('Search for Handytarife')
Scenario(`When I search for "Handytarife" without specifying any details Then I will get a list of various tariffs`,
async (I) => {
const toNumber = arr => arr.map(priceAsStr => Number(priceAsStr.replace(' €', '').replace(',', '.')))
I.amOnPage('https://www.check24.de/handytarife')
const cookieDialog = {
domain: '.check24.de',
httpOnly: false,
name: 'c24cb',
path: '/',
secure: false,
value: '1'
}
await I.setCookie(cookieDialog)
await I.refreshPage()
// Test will fail here
I.click('jetzt vergleichen', 'button')
I.waitInUrl('/handytarife/vergleich')
I.see('Handytarife im Vergleich', 'h1')
I.seeElement('//filter')
I.seeElement('product-item')
})
As far as I can see in lib/helper/puppeteer the problem is in findElements(…) and the following code will fix the above problem:
async function findElements(matcher, locator) {
// console.log('findElements', await (await matcher.getProperty('innerText')).jsonValue(), locator)
locator = new Locator(locator, 'css');
if (!locator.isXPath()) {
const matcherInnerText = await (await matcher.getProperty('innerText')).jsonValue();
if (matcherInnerText.indexOf(locator) >= 0) return [matcher]
return matcher.$$(locator.simplify());
}
return matcher.$x(locator.value);
}
Details
- CodeceptJS version: 1.2.1
- NodeJS Version: 8.9.4
- Operating System: Windows
- Puppeteer
- Configuration file:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
I.click(text, context) not working with Puppeteer #1127 - GitHub
I want to click a button in a test using I.click(buttonText, 'button') What do ... I.click(text, context) not working with Puppeteer #1127.
Read more >Unable to Click Button Using Puppeteer - Stack Overflow
click (); Here is my script: const puppeteer = require( 'puppeteer' ); ( async() => { var url = 'https://www.example.com'; const browser =...
Read more >puppeteer - npm
A high-level API to control headless Chrome over the DevTools Protocol. Latest version: 19.3.0, last published: 12 days ago.
Read more >Web Scraping with a Headless Browser: A Puppeteer Tutorial
In this article, Toptal Freelance JavaScript Developer Nick Chikovani shows how easy it is to perform web scraping using a headless browser.
Read more >Testing with Puppeteer - CodeceptJS
It's readable and simple and works using Puppeteer API! # Setup. To start you need CodeceptJS with Puppeteer packages installed. npm install ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are trying to click
span
element, and it’s not generally clickable. So, you should use explicit way to point the elementThis will do the trick (I used xpath to make finding text easier)
Came across the same issue because the text is in a div rather than a clickable element such as a button. Solved by specifying the element to click instead of the text content itself.