Estoy automatizando un sitio web en el que quiero hacer clic en la x cuando aparece una ventana emergente de suscripción. El HTML para la X es
<button title="Close popup message" data-testid="email-popup-close-button" id="email-popup-close-button" class="dw-1hfj58t-CloseBtn--EmailContainer e1lwf35p0">×</button>Entonces, para hacer clic en esto, estoy usando lo siguiente
await driver.findElement(By.id("email-popup-close-button")).click();Pero aparece el siguiente error.
NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="email-popup-close-button"]"} 
Parece que el problema con el localizador. Prueba a continuación.
await driver.findElement(By.xpath("(//button[normalize-space()='×'])[1]")).click();O
await driver.findElement(By.xpath("//button[@title='Close popup message']")).click();O
WebDriverWait wait = new WebDriverWait(driver,30); elem = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@title='Close popup message']"))); elem.click();Importar:
import org.openqa.selenium.By import org.openqa.selenium.WebDriver import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWaitAvísame si esto no funciona.
Encontré la respuesta Declaré esto const {Builder, By, Key, until} = require("selenium-webdriver");
y usado
let query = driver.wait(until.elementLocated(By.id('email-popup-close-button'))); await query.click();