Selenio:Selenio: Scorrere fino alla fine della pagina
Sono nuovo di WebDriverJS. Ho provato questo approccio in Java.
Long repaeted = 0l, scrollHeight = 0l, returnHeight = 0l;
while(true){
if (repaeted == 0) {
returnHeight = (Long) jse.executeScript("var scroll =document.documentElement.scrollHeight;window.scrollTo(0, scroll); return scroll;");
System.out.println("Height : "+scrollHeight +"\t Chnage : "+returnHeight+ "\t Repeated : "+repaeted);
scrollHeight = returnHeight;
}else {
returnHeight = (Long) jse.executeScript("var scroll = document.documentElement.scrollHeight;window.scrollTo(0, scroll); return scroll;");
System.out.println("Height : "+scrollHeight +"\t Chnage : "+returnHeight+ "\t Repeated : "+repaeted);
if (scrollHeight.intValue() == returnHeight.intValue()) {
System.out.println("Break.."+ returnHeight);
break;
} else { scrollHeight = returnHeight; }
}
repaeted++;
}
ma sto affrontando problema in webdriverjs mentre l'iterazione del ciclo.
var webdriver = require('..'),
By = webdriver.By,
until = webdriver.until;
// make sure chromedriver can be found on your system PATH
var driver = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.build();
driver.get('https://in.yahoo.com/').then(function(){
var window = new webdriver.WebDriver.Window(driver);
window.maximize();
driver.manage().timeouts().implicitlyWait(1000 * 3);
})
.then(function(){
console.log('Entered');
var check = 0, count = 0
for(var i = 0; i< 50; i++){
//driver.sleep(1000 * 2);
driver.executeScript('var dynamicscroll = document.documentElement.scrollHeight;window.scrollTo(0, dynamicscroll);return dynamicscroll;').then(function(height){
console.log('Check : '+check+' Height : '+height +' Repeated : '+(count++));
if(check === 0 || check !== height){console.log('continue'); check = height; }
else { console.log('break'); i = 100; }
});
}
})
.then(null, function(err) {
console.error("An error was thrown! By Promise..." + err);
});
driver.quit();
Nel mio codice ho hardcoded ciclo for per iterare fino a 50 volte e voglio uscire/rompere il ciclo quando si raggiunge l'altezza di scorrimento per finire. Con questo approccio, voglio rimuovere hardcode come java-code perché non so quante volte per iterare per altre applicazioni il cui scorrimento è tenuto ad aumentare dinamicamente. Per esempio, l'applicazione Facebook, Yahoo News ...
Puoi verificare con questo URL: 'https: // in.yahoo.com /'. e la mia domanda è che voglio interrompere il ciclo quando raggiunge la fine usando 'webdriverjs.' quale URL hai selezionato contiene' div scroll'. – Yash
@Yash, funziona con https://in.yahoo.com/. La tua domanda è come scorrere verso il basso fino alla fine di una pagina Web quando l'altezza di scorrimento aumenta dinamicamente, che è esattamente ciò che questo esempio fa con 'webdriverjs'. Ho aggiunto un altro esempio che scorre fino a quando l'altezza non aumenta più durante un tempo specifico. –
Puoi verificare che il codice stia generando l'errore 'ScriptTimeoutError: timeout di script asincrono: il risultato non è stato ricevuto in 0 secondi ogni volta durante l'esecuzione. – Yash