WebElement click在Selenium中不起作用

问题描述

我正在https://www.yatra.com/etw-desktop/学习自动化的硒测试。尝试单击名为“亚洲”的图像按钮(已附加图像)时,出现超时异常。请帮助我找出问题所在。

driver.manage().window().maximize();
        
driver.get("https://www.yatra.com/etw-desktop/");
driver.manage().timeouts().implicitlyWait(4000,TimeUnit.MILLISECONDS);
Thread.sleep(5000);
        
new webdriverwait(driver,20).until(ExpectedConditions.elementToBeClickable
(By.xpath("//*[@id=\"scrollable1\"]/div[1]/div/a[2]/div[4]"))).click();
Thread.sleep(4000);
        
Assert.assertEquals("https://www.yatra.com/etw-desktop/city-list",driver.getcurrenturl());

image showing the web element to be clicked

解决方法

最可能是因为使用了Thread.sleep(),这是显式等待的最坏情况。而是使用硒本身提供的wait方法。

,

尝试一下:

programmatic injection