等待模态定位



我在检测模态是否处于使用的位置时遇到问题

wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable((WEAsesor.BtnColumnas))).Click();

但是当模态在DOM中时,它会一直上升到指令检测到的位置,但我无法对元素执行任何操作,因为还没有这个位置,你知道如何解决这个问题吗?

您可以编写自定义等待实现,如:

wait.Until(element => /* Do something with the element */);

因此,如果你想等待一个位置,你可能应该先(手动(等待,看看你想要的位置是什么。例如:

int expectedLocationX = WEAsesor.BtnColumnas.Location.X;
int expectedLocationY = WEAsesor.BtnColumnas.Location.Y;

在你知道元素的预期位置后,写下你的等待:

/* you set whatever the X or Y is, in this example, 10 */
int expectedLocationX = 10; 
int expectedLocationY = 10; 
wait.Until(driver => 
{
bool isXCorrect = WEAsesor.BtnColumnas.Position.X == expectedLocationX;
bool isYCorrect = WEAsesor.BtnColumnas.Position.Y == expectedLocationY;
/* This code will return *true* only if both the X and Y are correct.*/
return isXCorrent && isYCorrect;
});

从本质上讲,wait.Until(driver => ...)方法说,"在这里,如果你愿意,就使用驱动程序,做你的事情,当你希望我停止等待时,返回true。如果你返回false或null,我将继续运行...,等待你返回true或non-null。

因此,告诉wait对象,等待元素到达预期位置。

最新更新