Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
¿Por qué no puedo deshacerme de un menú contextual con Selenium o Javascript de fuerza bruta?

He intentado casi todo, pero no puedo deshacerme del menú contextual. Pasos

  1. Haga clic derecho en el menú contextual.
  2. Aceptar alerta
  3. Intenta deshacerte del menú contextual.

Manualmente, el menú contextual desaparece, pero no a través de la automatización. Aquí está el código. Tratando de entender lo que está sucediendo debajo del capó. Cualquier herramienta/lenguaje de automatización para una explicación está bien.

 By contextMenuBox = By.cssSelector("div#hot-spot"); By contextMenuTitle = By.xpath("//h3[text()='Context Menu']"); By body = By.xpath("//html"); WebDriver driver = DriverManager.getDriver(); driver.get("https://the-internet.herokuapp.com/context_menu"); driver.manage().window().maximize(); String windowHandle = driver.getWindowHandle(); WebDriverWait wait = new WebDriverWait(driver, 10); WebElement contextEle = wait.until(ExpectedConditions.visibilityOfElementLocated(contextMenuBox)); Actions action = new Actions(driver); action.moveToElement(contextEle).contextClick().build().perform(); Thread.sleep(1000); //Just a Debug step Alert alert = driver.switchTo().alert(); alert.accept(); driver.switchTo().window(windowHandle); System.out.println(driver.findElement(contextMenuTitle).getText()); Thread.sleep(5000); //Just a Debug step /* * Trying to click using javascript. * element.click() as well as creating a mouse click event on the element and then * dispatching */ SeleniumUtility.click(body,0,0); driver.findElement(body).click(); Actions newAction = new Actions(driver); newAction.moveToElement(driver.findElement(contextMenuTitle)).click().build().perform(); newAction.sendKeys(Keys.ESCAPE).perform(); Thread.sleep(2000); //Just a Debug step

Actualización: lo único que funciona es el uso de la clase Robot

 Robot robot3 = new Robot(); robot3.keyPress(KeyEvent.VK_ESCAPE); robot3.keyRelease(KeyEvent.VK_ESCAPE);

¿Alguien tiene una explicación de por qué las cosas ocultas de Selenium y Javacript no funcionan?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!