কম্পিউটার

কিভাবে xpath ব্যবহার করে nম উপ উপাদান সনাক্ত করতে হয়?


আমরা নিচের উপায়ে xpath ব্যবহার করে nth সাব এলিমেন্ট সনাক্ত করতে পারি -

  • সূচকের সাথে বর্গাকার বন্ধনী যোগ করে।

  • xpath এ অবস্থান () পদ্ধতি ব্যবহার করে।

উদাহরণ

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class SubElement {
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      String url = "https://www.tutorialspoint.com/index.htm";
      driver.get(url);
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      // xpath using position() targeting the first element with type text
      driver.findElement(By.xpath("//input[@type='text'][position()=1]"))
      .click();
      driver.close();
   }
}

উদাহরণ

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class RowCount {
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      String url = "https://www.tutorialspoint.com/plsql/plsql_basic_syntax.htm";
      driver.get(url);
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      // xpath with index appended to get the data from the row 2 of table
      List<WebElement> rows =
      driver.findElements(By.xpath("//table/tbody/tr[2]/td"));
      System.out.println(“The number of data in row 2 is “+ rows.size());
      driver.close();
   }
}

  1. কিভাবে জাভাস্ক্রিপ্ট ব্যবহার করে পিতামাতার শিশু উপাদান পেতে?

  2. কিভাবে C++ এ STL ব্যবহার করে একটি অ্যারের সর্বোচ্চ উপাদান খুঁজে পাবেন?

  3. C# এ পুনরাবৃত্তি ব্যবহার করে ফিবোনাচি সিরিজের nম মান কীভাবে পাবেন?

  4. পাইথন ব্যবহার করে তালিকায় উপাদান কীভাবে যুক্ত করবেন?