You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术咨询:求指定Ruby代码对应的Selenium WebDriver Java代码

Converting Ruby Selenium Code to Java for FlyDubai Date Picker

No problem! Let's translate that Ruby Selenium line into Java and slot it into your existing FlyDubai date picker test smoothly.

First, here's the direct Java equivalent of your Ruby code:

driver.findElements(By.cssSelector("button[data-pika-year='2017'][data-pika-month='11'][data-pika-day='22']")).get(0).click();

Quick Conversion Breakdown:

  • Selenium Java uses findElements just like your Ruby code, which returns a list of matching web elements.
  • Grabbing the first element with .get(0) works identically in both languages.
  • The CSS selector string stays exactly the same—it's language-agnostic, so no tweaks needed there.

Here's the full integrated test method with this date selection line added:

public void FlyDubaiDatePickerTest() throws InterruptedException {
    // Go to website
    driver.get("https://www.flydubai.com/en/");
    
    // *****Departure day selection started.
    // Click Departure Date
    driver.findElement(By.id("departureDate")).click();
    
    // Select the specific target date (converted from Ruby code)
    driver.findElements(By.cssSelector("button[data-pika-year='2017'][data-pika-month='11'][data-pika-day='22']")).get(0).click();
    
    // Add any follow-up test steps you need here
}

One small reminder: Double-check that you've imported all required Selenium classes (like org.openqa.selenium.By and org.openqa.selenium.WebDriver) at the top of your Java file to avoid compilation issues.

内容的提问来源于stack exchange,提问作者Fatna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:53:32