css - 使用 CSS 选择器选择下拉值

标签 css selenium automation

<分区>

这是我现有的代码:

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 org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class VirginTrains {

public static void main(String[] args) throws InterruptedException {

String projectPath = System.getProperty("user.dir");
System.out.println("projectPath : " + projectPath);

// THE FOLLOWING CODE IS FOR 1.Journey details
//Opens virgin trains web page
System.setProperty("webdriver.chrome.driver", projectPath + 
"\\drivers\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.virgintrains.co.uk/");

//The following maximise the screen size
driver.manage().window().maximize();

在下面的代码中,我想在下拉菜单中选择 Arriving by

// click to open the date time picker calendar - 4th Box
Actions actions1 = new Actions(driver);
WebElement departArrive = 
driver.findElement(By.cssSelector("span[class='dropdownLabel']"));
actions1.doubleClick(departArrive).perform();


   driver.findElement(By.cssSelector("span[class='dropdownLabel']")).click();
   driver.findElement(By.cssSelector("css=input.Arriving by")).click();

一旦代码运行,它应该选择 Arriving by

最佳答案

我能看到,你想要:

[data-value="Arrive Before"]

下次只需检查您的元素面板并选择一个属性来选择它。

关于css - 使用 CSS 选择器选择下拉值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55659466/

上一篇:html - 为什么我的控件没有分成每行 3 个控件?

下一篇:html - 如何通过选项卡结构访问悬停状态显示的文本?

相关文章:

c# - 我为什么可以将 IWebDriver 转换为 IJavaScriptExecutor?

javascript - 如何在python-selenium中获取html元素的 'value'?

java - Selenium/Java - 使用 PLUpload 上传文件

php - 如何将 CSS 应用于提交按钮

javascript - 在鼠标悬停时为 td 着色

jQuery - 添加元素并影响不同元素的 HTML

testing - 有人使用可执行需求吗?

html - 更改列表字体大小会重新调整整个列表的大小

java - 在Java中,什么命令行可以让计算机点击屏幕?

linux - 使用脚本通过 SSH 自动执行任务