2017-02-12 25 views
0

webdriverjsを使用していますが、webelementの親IDを取得したいと思います。行という複数のクラスがありますが、それぞれ異なるIDがあります。課題は、メッセージが送信されたときにIDが生成されることです。だから私はクラスでinnerHtmlをつかんで、IDを取得しようとすることができます。私は以下のhtmlを持って 、javascript seleniumを使用して親div IDを取得する方法は?

<div class="row" id="4003"> 
<div class="client-chat"> 
<p class="client-chat-text">If you have any questions, don’t hesitate to message me. I’m here to help with whatever you need!<span class="chat-time">Feb 01 2017 11:30:57</span></p> 
</div> 
</div> 

<div id="4361" class="row"> 
<div class="coach-chat"> 
<p class="coach-chat-text"> 
hi 
</p> 
</div> 

ID(4361)である私は私のテストのために取得する必要があり、生成うちの1つである第2のdiv。ただし、コーチチャットテキストを取得できます。どのように私はセレンの親要素を取得するのですか?私は以下のコードを試したが、私は親のIDを取得する方法を知らない。親要素を見つけるために - /parent::node() - あなたは「コーチ・チャット・テキスト」のクラスを持つ要素を見つけるためにwebdriver.By.xpathを使用する場合は

it('send a text message now',function(done){ 
      driver.findElement(webdriver.By.css("#messageField")).sendKeys('Hi'); 
      driver.sleep(1000); 
      driver.findElement(webdriver.By.xpath(".//*[@id='sendMessage']")).click().then(function(){ 
       driver.findElement(webdriver.By.className("coach-chat-text")).getText().then(function(text){ 
        var message = text.slice(0,2); 
        //i want to fetch the parent id here. 
        try { 
         expect(message).to.equal("www.pluma.co"); 
         done(); 
        } catch (e) { 
         done(e); 
        } 
       }); 
      }); 
     }); 
    }); 

答えて

0

することは、あなたは、XPath親セレクタを使用することができます。次のような

何か、あなたのXPathはおそらく異なりますが、:

driver.findElement(webdriver.By.xpath(".//*[contains(@class, 'coach-chat-text')]/parent::node()"));

関連する問題