簡體   English   中英

如何使用Selenium Webdriver單擊具有特定文本的div?

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

我正在使用Selenium Webdriver在JavaScript中測試程序。

我想在搜索框中輸入一些數據后點擊我得到的元素。 問題在於,由於我沒有創建該對象,因此在測試時我不能給它一個id並引用它。

有沒有辦法引用包含特定文本的標簽?

  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);
});

如果您希望使用jquery找到該元素,請使用contains選擇器

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

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

要么

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

希望這可以幫助你......

我找到了一種方法,通過選擇我想要點擊的鏈接的文本,使用以下語法:單擊此TextHere我可以.click('link = TextHere'),它將選擇該元素..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM