I used xpath for getting the paragraph text, it works fine for first paragraph but second and third paragraph it is not working fine. it shows empty in console output.
Following string are the ones which i have faced the issue - String secondAns , String thirdAns
[Note : I did not face any issue as element not found for second and third paragraph ]
driver.get("https://demoqa.com/widgets");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//span[text()='Accordian']")).click();
//clicking the left menu
//First Paragraph
String firstques = driver.findElement(By.xpath("//div[@id='section1Heading']")).getText();
System.out.println("First Question : " + firstques);
String firstAns = driver.findElement(By.xpath("//div[@id='section1Content']//p[1]")).getText();
System.out.println("First Answer : " + firstAns);
//Second Paragraph
String secondques = driver.findElement(By.xpath("//div[@id='section2Heading']")).getText();
System.out.println("Second Question : " + secondques);
String secondAns = driver.findElement(By.xpath("//div[@id='section2Content']//p[1]")).getText();
System.out.println("Second Answer : " + secondAns);
//Third Paragraph
String thirdques = driver.findElement(By.xpath("//div[@id='section3Heading']")).getText();
System.out.println("Third Question : " + thirdques);
String thirdAns = driver.findElement(By.xpath("//div[@id='section3Content']//p[1]")).getText();
System.out.println("Third Answer : " + thirdAns