<分区>
<分区>
这是我现有的代码:
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/