0

I can't capture with findElement the class, xpath etc. in:

  1. https://economia.estadao.com.br/noticias/geral,por-que-nao-tres-em-uma,70002648617
  2. click on: entre aqui para ler a matéria.

I already tried several ways.

My code is

public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver","C:\\ESTADAO\\Browsers\\geckodriver.exe"); 
    WebDriver navegador = new FirefoxDriver();  
    navegador.get("economia.estadao.com.br/noticias/…); 
    navegador.manage().window().maximize(); 
    navegador.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
    navegador.findElement(By.xpath("/html/body/div/div/div[2]/div[1]/div[2]/div/a/div[2]")).click(); 
}

enter image description here

3
  • What ways? What happened? Give an actual example.
    – jonrsharpe
    Commented Mar 5, 2019 at 21:49
  • Hi Jon, Please, I need to access the site economia.estadao.com.br/noticias/… and to click on: "entre aqui para ler a matéria".
    – saulik
    Commented Mar 5, 2019 at 21:53
  • Yes, I understood that from the question. It's unclear what problem you've had in trying to implement that.
    – jonrsharpe
    Commented Mar 5, 2019 at 21:54

3 Answers 3

0

Try this Xpath

//b[contains(text(),'entre aqui para ler a matéria ')]

This will work.

-1

Since the text is within the a tag, the following will work:

findElement(By.cssSelector("a[href*='login']")).click()

2
  • Hi Friends, I'm trying but without success. For now I thank you very much. If someone wants to access the site and try to capture I'm happy. But I'll try the solutions you sent.
    – saulik
    Commented Mar 7, 2019 at 14:58
  • Hi Friends I've tried every possible command, I've honestly never seen anything like it. I have even used advanced commands from the site saucelabs.com/resources/articles/selenium-tips-css-selectors and I did not succeed. If anyone can, I'll pay for lunch, but for me, that's enough !! The path to this is: economia.estadao.com.br/noticias/… and click on: entre aqui para ler a matéria Very grateful to all who tried to help me !.
    – saulik
    Commented Mar 8, 2019 at 21:21
-2

Most modern browsers support developer mode. Use "inspector" to copy xpath of the element you are interested in. For your example:

/html/body/div/div/div[2]/div[1]/div[2]/div/a/div[1]/b
2
  • 2
    This kind of xpath locator use is bad practice, and why xpath has a reputation of being terrible in the test automation community. Using an absolute xpath of this length has a high probability of breaking with any HTML change.
    – anonygoose
    Commented Mar 7, 2019 at 12:56
  • Right, but still valid and easy way to get started.
    – codach
    Commented Mar 7, 2019 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.