网站是 https://www.nseindia.com/get-quotes/derivatives?symbol=AARTIIND
我使用“wait.until(ExpectedConditions...”等待“选项链”元素加载,然后单击它。此后会出现一个表格,但尽我所能,我无法让程序等待它加载加载,除了粗略的 Thread.sleep 命令。
我尝试过底行写着“tot”,右上角写着“底层:”,但它们似乎都在表格之前加载。我尝试过“numberOfElementsToBeMoreThan”并放置“tr”xpath的定位器,如下所示:
try {
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.xpath("/html/body/div[10]/div[1]/div/section/div/div/div/div/div[1]/div[2]/div/div/div/div[2]/div[2]/div[2]/div/table[1]/tbody/tr"), 10));
} catch (Exception e) {
有什么办法可以做到这一点吗?我不明白“陈旧”属性,这有什么用吗?
**Solution 1:**
Please try the below mechanism, actually, it will be polling every second and it stops the polling once you it get the desired element, it might work for you.
FluentWait<WebDriver> wait = new FluentWait<> (driver)
.withTimeout (10, TimeUnit.SECONDS)
.pollingEvery (1, TimeUnit.SECONDS)
.ignoring (NoSuchElementException.class);
// Define the locator of the element to be clicked
By locator = By.id("");
// Wait until the element is clickable
WebElement element = wait.until (ExpectedConditions.elementToBeClickable (locator));
// Click on the element
element.click();
**Solutions 2:**
here you can use if-else condition to wait for until desired element.
boolean WaitforThisElement=driver.findelement(By.xpath("pass the path of the waiting elememnt").isDisplayed();
if(WaitforThisElement==true)
{
//write the code for the further activities.
}
else
{
//wait for the 10 seconds.
Thread.wait(10000);
}