Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

301
Vistas
¿Por qué el Selector de fecha en Selenium (usando JavaScript para la aplicación Spice Jet) no toma el valor del atributo?

Estoy usando JavaScript para el selector de fechas en Selenium. Mi código se ejecuta correctamente pero la fecha no está seleccionada en el selector de fechas.

 public class SpicJetBooking { static WebDriver driver; public static void main(String[] args) throws InterruptedException { ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-notifications"); System.setProperty("webdriver.chrome.driver","C:\\Downloads\\chromedriver.exe"); driver = new ChromeDriver(options); driver.manage().window().maximize(); driver.manage().deleteAllCookies(); driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10)); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); driver.get("https://www.spicejet.com/"); System.out.println("Site Opened"); Thread.sleep(3000); driver.findElement(By.xpath("//div[contains(text(),'round trip')]")).click(); // driver.findElement(By.xpath("//div[@data-testid='return-date-dropdown-label-test-id']")).sendKeys("Wed, 23 Mar 2022"); // WebElement element = driver.findElement(By.xpath("//div[contains(text(),'Return Date')]")); WebElement element = driver.findElement(By.xpath("//div[@data-testid='return-date-dropdown-label-test-id']")); // element.click(); String datVal = "Wed, 23 Mar 2022"; selectDateByJS(driver, element, datVal); System.out.println("Complete Execution"); } public static void selectDateByJS(WebDriver driver,WebElement element, String datVal){ JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("argument[0].setAttribute('value','"+datVal+"');", element); // String scriptVal = "arguments[0].setAttribute('value','\"+datVal+\"')"; // String scriptVal = "arguments[0].setAttribute('value','12-Mar-2022')"; // js.executeScript(scriptVal, element); System.out.println("JS Executed"); } }

Me referí a Selección de la fecha del calendario de JavaScriptExecutor en selenium , pero en mi opinión, el selector de fecha ha cambiado y esto no funciona ahora

Lo más destacado es la estructura HTML DOM de Departure

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Lo intenté:

 $x("(//div[text()='Return Date'])/following-sibling::div/child::div")[0].innerText = 'Wed, 23 Mar 2023'

y me funciona bien. Entonces necesitas usar:

 (//div[text()='Return Date'])/following-sibling::div/child::div** xpath as a locator and update your **selectDateByJS

línea de método donde realiza js

 js.executeScript("argument[0].innerText="+datVal, element);

Código completo:

 public class SpicJetBooking { static WebDriver driver; public static void main(String[] args) throws InterruptedException { ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-notifications"); System.setProperty("webdriver.chrome.driver","C:\\Downloads\\chromedriver.exe"); driver = new ChromeDriver(options); driver.manage().window().maximize(); driver.manage().deleteAllCookies(); driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10)); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); driver.get("https://www.spicejet.com/"); System.out.println("Site Opened"); Thread.sleep(3000); driver.findElement(By.xpath("//div[contains(text(),'round trip')]")).click(); WebElement element = driver.findElement(By.xpath("(//div[text()='Return Date'])/following-sibling::div/child::div")); String datVal = "Wed, 23 Mar 2022"; selectDateByJS(driver, element, datVal); System.out.println("Complete Execution"); } public static void selectDateByJS(WebDriver driver,WebElement element, String datVal){ JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("argument[0].innerText="+datVal, element); System.out.println("JS Executed"); } }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda