Tell me please. The task is to open the website www.random.org , click on the Numbers - Integers button. Then click Get Numbers and display the numbers in the console. I work with selenium webdriver , java and intellige idea. I came across a problem that I can not find the item through cssSelector .

 import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Basic { public static void main(String[] args) { WebDriver webBrowser = new ChromeDriver(); webBrowser.get("https://www.random.org/"); webBrowser.findElement(By.cssSelector("ЧТО ТУТ ПИСАТЬ")).click(); } } 

    2 answers 2

    If the element has id = "example", then write

     webBrowser.findElement(By.cssSelector("#example")).click(); 

    If the element has class = "example", then write

     webBrowser.findElement(By.cssSelector(".example")).click(); 

    Be sure to read the article on the site , otherwise it will not be possible to work normally.

    • thanks figured out the first part. - Igor
    • Now how to output to the console: System.out.println (webBrowser.findElements (By.cssSelector ("pre [class = 'data']"))); but displays some kind of nonsense. What's wrong? - Igor
    • If you understand, you need to mark as an answer and ask a new question - Yuri Bezrukov

    Tell me please. The task is to open the website www.random.org, click on the Numbers - Integers button. Then click Get Numbers and display the numbers in the console. I work with selenium webdriver, java and intellige idea. I came across a problem that I can not display the result in the console.

     import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Basic { public static void main(String[] args) { WebDriver webBrowser = new ChromeDriver(); webBrowser.get("https://www.random.org/"); webBrowser.findElement(By.cssSelector("a[href='/#numbers']")).click(); webBrowser.findElement(By.cssSelector("a[href='https://www.random.org/integers/']")).click(); webBrowser.findElement(By.cssSelector("input[value='Get Numbers']")).click(); System.out.println(webBrowser.findElements(By.cssSelector("pre[class='data']"))); } }