我正在访问理光打印机的Web界面。我无法识别用户名和密码字段。通常,我“检查”表单元素并复制“ CSS选择器”。此方法适用于其他形式,但不适用于此形式。这是复制的“ CSS选择器”:
body > table:nth-child(1) > tbody:nth-child(3) > tr:nth-child(6) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)
在检查时,这是用户名字段:
<input name="userid_work" type="text" size="50" style="background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAAAXNSR0IArs4c6QAAAUBJREFUOBGVVE2ORUAQLvIS4gwzEysHkHgnkMiEc4zEJXCMNwtWTmDh3UGcYoaFhZUFCzFVnu4wIaiE+vvq6+6qTgthGH6O4/jA7x1OiCAIPwj7CoLgSXDxSjEVzAt9k01CBKdWfsFf/2WNuEwc2YqigKZpK9glAlVVwTTNbQJZlnlCkiTAZnF/mePB2biRdhwHdF2HJEmgaRrwPA+qqoI4jle5/8XkXzrCFoHg+/5ICdpm13UTho7Q9/0WnsfwiL/ouHwHrJgQR8WEwVG+oXpMPaDAkdzvd7AsC8qyhCiKJjiRnCKwbRsMw9hcQ5zv9maSBeu6hjRNYRgGFuKaCNwjkjzPoSiK1d1gDDecQobOBwswzabD/D3Np7AHOIrvNpHmPI+Kc2RZBm3bcp8wuwSIot7QQ0PznoR6wYSK0Xb/AGVLcWwc7Ng3AAAAAElFTkSuQmCC"); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%; cursor: auto;" autocomplete="off">
我尝试了各种排列,userid_work等,但都没有用。基本上是我要做什么?
const USERNAME_SELECTOR = 'body > table:nth-child(1) > tbody:nth-child(3) > tr:nth-child(6) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)';
await page.click(USERNAME_SELECTOR);
await page.keyboard.type(CREDS.username);
因此,我正在考虑打印表单元素,然后查看返回的内容。除非有人告诉我该如何引用该用户名字段?
尝试了此表单元素的各种排列。
答案 0 :(得分:0)
我不知道您想做什么(单击或键入)
因此,请尝试单击输入:
await page.click('input[name="userid_work"]');
在输入中键入文本:
await page.type('input[name="userid_work"]', text);
使用javascript单击元素:
await page.$eval('input[name="userid_work"]', e => e.click);
使用javascript输入元素:
await page.$eval('input[name="userid_work"]', e => e.value = 'text');