2023创建 css 表达式有哪些不同的方法?

 所属分类:web前端开发

 浏览:43次-  评论: 0次-  更新时间:2023-09-06
描述:更多教程资料进入php教程获得。 下面列出了创建 css 表达式的不同方法 -使用类作为 css 选择器这将选择所有该特定类的网络元...
更多教程资料进入php教程获得。

创建 css 表达式有哪些不同的方法?

下面列出了创建 css 表达式的不同方法 -

  • 使用类作为 css 选择器

    这将选择所有该特定类的网络元素。 (用 (.) 表示,例如 - .classname)

  • 使用 id 作为 css 选择器。

    这将选择该特定 id 的 Web 元素。 (例如用 (#) 表示 - #ID)

  • 使用标记名和属性值作为选择器。

    这将选择该对象的 Web 元素特定的属性值组合。 (由标记名[attribute='value']表示)

示例

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 CssExpression {
   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().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
      //Using class with . For css expression
      driver.findElement(By.cssSelector(".gsc- input")).sendKeys("Selenium");
      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 CssId {
   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().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
      //Using id with # for css expression
      driver.findElement(By.cssSelector("#gsc-i- id1")).sendKeys("Selenium");
      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 CssTagExp {
   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().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
      //Using id tagname attribute combination for css expression
      driver.findElement(By.cssSelector("input[name=’search’]")).
      sendKeys("Selenium");
      driver.close();
   }
}

 标签:
积分说明:注册即送10金币,每日签到可获得更多金币,成为VIP会员可免金币下载! 充值积分充值会员更多说明»

讨论这个素材(0)回答他人问题或分享使用心得奖励金币

〒_〒 居然一个评论都没有……

表情  文明上网,理性发言!