外向小朋友
2019-06-12 15:44
采纳率: 61.5%
浏览 571

<a href="javascript:void(0);" class="bars">::before ::after</a>怎么选取该标签?

::before ::after怎么选取该标签?因为需要对其进行其他js得操作,需要选取,用.bars和class::before都选取不到

改过的
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch({
headless: false,
timeout: 30000,
});
const page = await browser.newPage();
await page.goto('http://localhost:62114/Account/Login?ReturnUrl=%2F');
//await page.waitFor(500);
await page.click("a[data-target='#TenantChangeModal']")
await page.waitFor(1000);
//await page.waitForSelector("input[name='TenancyName']");
await page.type("input[name='TenancyName']",'Default',{delay:100})
await page.waitFor(500);
await page.click('.btn.btn-primary.save-button.waves-effect');
await page.waitFor(2000);
await page.type("input[name='usernameOrEmailAddress']",'admin',{delay:100});

await page.waitFor(500);
await page.type("input[name='Password']",'123qwe',{delay:100});
const navigationPromise = page.waitForNavigation();
await page.click('#LoginButton'); //然后点击


await page.waitFor(3000);



    await page.click( css('.bars::after{content:\'test\';font-size:80px;}'));
    //await page.click("a[class='bars::before']"); //然后点击

})();
var css=function(t,s){
s=document.createElement('style');
s.innerText=t;
document.body.appendChild(s);
};

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 听楼一夜雨 2019-06-12 16:25
    已采纳
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    
    
    </head>
    
    <body>
    <style>
        p:after{content:'测试'}
    </style>
    <p class="bars">正文内容</p>
    
    <script>
    var css=function(t,s){
        s=document.createElement('style');
        s.innerText=t;
        document.body.appendChild(s);
    };
    
    document.onclick=function(){
         css('.bars:after{content:\'test\';font-size:80px;}');//放在对应触发事件里面就行
    };
    </script>
    </body>
    </html>
    
    
    已采纳该答案
    打赏 评论
  • 战渣渣 2019-06-12 16:23

    不知道你是用的啥框架之类的,给一个原生的获取元素吧 —— document.getElementsByClassName("bars");

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
    <div id="a1">
        <a href="javascript:void(0);" class="bars">::before ::after</a>
        <input type="button" onclick="b_click()" value="获取bars标签">
    </div>
    
    <style>
        #a1 {
            float: left;
            width: 100px;
            height: 100px;
        }
    
        #a1 video {
            width: 100px;
            height: 100px;
        }
    </style>
    <script type="text/javascript">
        function b_click() {
            var a = document.getElementsByClassName("bars");
            alert(a[0].className);
            alert(a[0].href);
        }
    </script>
    </body>
    </html>
    
    
    打赏 评论
  • dabocaiqq 2019-06-13 09:48
    打赏 评论

相关推荐 更多相似问题