admin管理员组文章数量:1392086
I have to click the div
with title="Lista de Chamados"
. I've tried several different ways, but nothing works. The div
is draggable, so the last solution wouldn't solve it (and it does NOT work).
How can I click on div title="Lista de Tarefas"
(independently of its position)?
const puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
const URL = '/'
await page.goto(URL, {waitUntil: 'load'});
console.log(page.url());
const SELETOR_USUARIO = '#usuario';
const SELETOR_SENHA = '#senha';
const usuario = 'usr';
const senha = 'pass';
await page.type(SELETOR_USUARIO, usuario);
await page.type(SELETOR_SENHA, senha);
//console.log(page.url());
//FAZ LOGIN:
page.click('#login'),
page.waitForNavigation({ waitUntil: 'networkidle0' });
//browser.close();
};
scrape().then((value) => {
console.log(value);
});
--EDIT
...
//FAZ LOGIN:
await page.click('#login'),
//await page.waitForNavigation({ waitUntil: 'networkidle0' }) //espera nova página carregar
await page.waitForNavigation({waitUntil: "domcontentloaded"});
//await page.click('div[title="Lista de Tarefas"]'); //Error: No node found for selector: div[title="Lista de Tarefas"]
/* const seletor = 'div[title="Lista de Tarefas"]';
const botao = await page.$(seletor);
console.log(botao); //null
botao.click(); */
const botao = await page.evaluate( () => {
let b = document.querySelector('div[title="Lista de Tarefas"]');
console.log('in>>> ' + b); // b and b[0] are NULL
});
This is the code to the element I need to click:
<div class="menu-lateral-contraido-sub-container" title="Lista de Chamados" draggable="true" style="opacity: 1;">
<div to="/main/listachamado/" class="route-redirect-box">
<div class="menu-lateral-item-contraido-container cor-tema-topo-fundo ">
<div class="menu-lateral-item-contraido-icon"><i class="ellevo-icons">lista_chamado</i></div>
</div>
</div>
</div>
I have to click the div
with title="Lista de Chamados"
. I've tried several different ways, but nothing works. The div
is draggable, so the last solution wouldn't solve it (and it does NOT work).
How can I click on div title="Lista de Tarefas"
(independently of its position)?
const puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
const URL = 'https://dummy.br/'
await page.goto(URL, {waitUntil: 'load'});
console.log(page.url());
const SELETOR_USUARIO = '#usuario';
const SELETOR_SENHA = '#senha';
const usuario = 'usr';
const senha = 'pass';
await page.type(SELETOR_USUARIO, usuario);
await page.type(SELETOR_SENHA, senha);
//console.log(page.url());
//FAZ LOGIN:
page.click('#login'),
page.waitForNavigation({ waitUntil: 'networkidle0' });
//browser.close();
};
scrape().then((value) => {
console.log(value);
});
--EDIT
...
//FAZ LOGIN:
await page.click('#login'),
//await page.waitForNavigation({ waitUntil: 'networkidle0' }) //espera nova página carregar
await page.waitForNavigation({waitUntil: "domcontentloaded"});
//await page.click('div[title="Lista de Tarefas"]'); //Error: No node found for selector: div[title="Lista de Tarefas"]
/* const seletor = 'div[title="Lista de Tarefas"]';
const botao = await page.$(seletor);
console.log(botao); //null
botao.click(); */
const botao = await page.evaluate( () => {
let b = document.querySelector('div[title="Lista de Tarefas"]');
console.log('in>>> ' + b); // b and b[0] are NULL
});
This is the code to the element I need to click:
<div class="menu-lateral-contraido-sub-container" title="Lista de Chamados" draggable="true" style="opacity: 1;">
<div to="/main/listachamado/" class="route-redirect-box">
<div class="menu-lateral-item-contraido-container cor-tema-topo-fundo ">
<div class="menu-lateral-item-contraido-icon"><i class="ellevo-icons">lista_chamado</i></div>
</div>
</div>
</div>
Share
Improve this question
edited Oct 17, 2018 at 17:34
nanquim
asked Oct 10, 2018 at 22:20
nanquimnanquim
1,9248 gold badges34 silver badges51 bronze badges
1
- await page.$(selector, option) – Alston Commented Jul 6, 2022 at 5:44
1 Answer
Reset to default 4You can use the attribute selector, [title=""]
, inside page.click()
to click on an element by title:
await page.click('div[title="Lista de Tarefas"]');
本文标签: javascriptNodeJSPuppeteerClick on div by titleStack Overflow
版权声明:本文标题:javascript - NodeJSPuppeteer - Click on div by title? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744781092a2624717.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论