简体   繁体   中英

How do I click a div with a specific text using Selenium Webdriver?

I am using Selenium Webdriver to test a program in JavaScript.

I want to click on an element that I get after I input some data in a search box. The problem is that, as I don't create that object, I can not give it an id in and refer to it while I'm testing.

Is there a way to refer to a tag containing a specific text?

  it('Should select a song', function(done) {
  client
    .setValue('#email', 'partygoer@email.com')
    .setValue('#query', 'superstition')
    .click('#search')
    .waitFor('.cover', 5000)
    .click('Here I have to click on the element with the specific text')
    .click('#submit')
    .waitFor('#thank-you')
    .getText('#thank-you', function(err, text) {
      expect(text).to.include('hello partygoer@email.com, your song id is')
    })
    .call(done);
});

If you wish to find the element using jquery then use the contains selector

$('tagname[attribute]:contains("specific text")');

$('div:contains("searchterm")');

Or

$('div#test').filter(function(){ return $(this).text();});

Hope this helps you...

我找到了一种方法,通过选择我想要点击的链接的文本,使用以下语法:单击此TextHere我可以.click('link = TextHere'),它将选择该元素..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM