好的,我的代码,但它立即执行
private static ChromeDriver mainDriver;
mainDriver.Navigate().GoToUrl(srFetchUrl);
string srPageSource = mainDriver.PageSource;
我必须在页面实际导航到新页面并加载页面后获取源代码
答案 0 :(得分:0)
您可以尝试此方法,这将等到页面完全加载,您可以将预期时间添加到页面加载。
public void E_WaitForPageLoad() throws Exception
{
JavascriptExecutor js = (JavascriptExecutor)driver;
//This loop will rotate for 100 times to check If page Is ready after every 1 second.
//You can replace your if you wants to Increase or decrease wait time.
int waittime;
waittime = 60;
for (int i=0; i<waittime; i++)
{
try
{
Thread.sleep(1000);
}catch (InterruptedException e) {}
//To check page ready state.
if (js.executeScript("return document.readyState").toString().equals("complete"))
{
//System.out.println("Wait for Page Load : "+js.executeScript("return document.readyState").toString());
break;
}
}
System.out.println("\nWeb-Page Loaded.");
}
谢谢你,
Ed D,印度。
答案 1 :(得分:-1)
指定,隐式或显式等待,直到加载页面中的元素。
将此link引用为C#等待语法