Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
Not able to capture text using Selenium in Java

I am using Selenium in Java to capture values from the below code snippet. But it's returning a null value.

<div class="selenium" style="max-height: 0px !important; max-width: 0px !important;">
<div class="share metric">
<span id="nsf" class="nsf">
"2.2210636079249215+2.224479431183342+2.2244191794364805+2.2635962763351296+2.289855072463768+2.3309352517985613+2.3216783216783217+2.360018509949098+null+2.042235790730032+0.000006222369997702123+0</span></div>

I tried using

driver.findElement(By.xpath("//div[@class='share metric']/span[@id='nsf']")).getAttribute("value")

and

driver.findElement(By.xpath("//div[@class='share metric']/span[@id='nsf']")).gettext()
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Your xpath is wrong, the span tag is not a child of <div class="share metric">.

Why using xpath at all? Localting the element by it's id works just fine.

code:

    WebElement nsf = driver.findElement(By.id("nsf"));
    String text = nsf.getText();
    System.out.println(text);

output:

tarting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951@{#904}) on port 28658
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1655279888.338][WARNING]: This version of ChromeDriver has not been tested with Chrome version 102.
Čer 15, 2022 9:58:08 DOP. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
"2.2210636079249215+2.224479431183342+2.2244191794364805+2.2635962763351296+2.289855072463768+2.3309352517985613+2.3216783216783217+2.360018509949098+null+2.042235790730032+0.000006222369997702123+0
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda