English 中文(简体)
如何在DIV和Selenium网络司机中找到一个要素
原标题:How to find a element inside a DIV with Selenium WebDriver

我试图找到一种办法,以获得四分五裂的价值,但我不能从Xpath或Cselector那里找到这个要素。 在这两种情况下(Xpath和cssSelector),Eclipse console显示了错误信息:

org. openqa.selenium.NoSuchElementException: no such elements: 无法确定要素:{“方法”:“xpath”,“selector”:”/b[text(text)= Protocolo Único ]/following:span 1}

Using the xpath, I can find the value I need but, I can not get it and play in a variable. Below is the image with the HTML of the page and the xpath I made.

Xpath I ve created a method called verifyTextAssert that takes a By parameter and returns the text. The method below follows:

public String verifyTextAssert(By by) {

    return driver.findElement(by).getText();

}

在<> TratOsFatRoamPage I类制造了getNuPu方法,即verificationTextAssert方法,并将xpath带至这一方法,并应当归还其发现的价值。

private String obterNuPu() {

    return verifyTextAssert(By.xpath("//b[text()= Protocolo Único  ]/following::span[1]")); 

}

“entergraph

<fieldset style="margin-bottom:10px;">
    <div id="content_titulo">Informações Gerais</div>
    <div style="padding-top:10px; padding-bottom: 10px; padding-left:5px; height:150%;">
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">ID Atendimento </b> <br> <span>5574474205</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Protocolo Único </b> <br> <span>2018227017094</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"><b class="label_tratamento ">Data Abertura </b> <br> <span>21/03/2018</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Hora Abertura </b> <br> <span></span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"><b class="label_tratamento ">Nome do Cliente </b> <br> <span></span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Tipo Cliente </b> <br> <span></span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Motivo 1 </b> <br> <span>Reclamação</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Motivo 2 </b> <br> <span>Claro Conta</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Motivo 3 </b> <br> <span>Contestação</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Motivo 4 </b> <br> <span>Serviços</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Motivo 5 </b> <br> <span>Pacote de Internet</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Worklist </b> <br> <span>BackOfficeAjusteRoaming GE</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">CNPJ </b> <br> <span>19988702272</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">MSISDN </b> <br> <span>69993932002</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">MSISDN2 </b> <br> <span></span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Status PS8 </b> <br> <span>Pendente</span></div>
        <div style="float:left; width:24%; padding-top:5px; padding-bottom: 8px; padding-left:5px; height:30px; font-size:x-small;"> <b class="label_tratamento ">Quem Abriu </b> <br> <span></span></div><input type="hidden" name="Id_Estrategia_Logado" id="Id_Estrategia_Logado" value="359"><input type="hidden" name="Id_Atividade_Logado" id="Id_Atividade_Logado" value="0">

    </div>
</fieldset>
问题回答

似乎好像您的x。 Path是正确的。 一项建议试图在您的网页上找到。 如果是的话,请看你的内容是否在其中。 第二项建议是,如果不存在“异构”特性,则研究元素特性。

您可在社保学会下选取案文。

 driver.FindElement(By.CssSelector("body > fieldset:nth-child(1) > div:nth-child(2) > div:nth-child(2) > span:nth-child(3)"));

Edit

var element =  driver.FindElement(By.CssSelector("fieldset:nth-child(1) > div:nth-child(2) > div:nth-child(2) > span"));
string v = element.Text;




相关问题
VTD XML inner XPath Expressions

I have a xml file for example like this <root> <test> <bla>test1</bla> </test> <test> <bla>test2</bla> </test> <test> </test&...

C# XML adding/copying

With the following XML I am trying to copy and add to another XML but I haven t used the C# XML document objects before. So here is the XML <config> <configXML> <Connections&...

Filter SQL queries on the XML column using XPath/XQuery

I m having a table with one XML column. I d like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this ...

Python XPath Result displaying only []

Hey I have just started to use Python recently and I want to use it with a bit of xPath, the thing is when I print the result of the query I only get [] and I don t know why =S import libxml2, ...

热门标签