2013-07-19 13 views
9

Şu anda sayfalarda bazı doğrulama yapmak için Selenium Webdriver uygulamasını kullanıyorum. Webdriver, PhantomJS tarafından yönetiliyor. Bunu PhantomJS'de, aşağıdaki gibi bir örnek kullanarak ağı dinleyebilirsiniz: (https://github.com/ariya/phantomjs/wiki/Network-Monitoring).Selenyum Webdriver ve Python ile PhantomJS'yi Kullanma

var page = require('webpage').create(); 
page.onResourceRequested = function (request) { 
    console.log('Request ' + JSON.stringify(request, undefined, 4)); 
}; 
page.onResourceReceived = function (response) { 
    console.log('Receive ' + JSON.stringify(response, undefined, 4)); 
}; 
page.open(url); 

Webdriver içindeki bu işlevselliği nasıl sağlayabilirim? DesiredCapabilities'e bir işlev bağlayabilir miyim?

+0

Bu nasıl bir piton sorudur? – Marcin

+0

[Önerilen çözümler benim için işe yaramadı, ancak bu işe yarar (driver.execute_script kullanır)] (http://stackoverflow.com/a/36427562/1334996) – AlexMe

cevap

0

Burada ne elde etmeye çalışıyorsunuz? Javascript enjekte edilebilir. Böylece, sayfayı dinleyen bir nesne oluşturabilir ve bunu, bazı eylemlerde bulunduğunuzda yakaladığınız bir nesneye kaydedebilirsiniz.

Bunu bir deneyelim ama phantomJS'nin ne yaptığından emin değilim.

browser.execute_script("  
var requests= []; 
var received = []; 
var page = require('webpage').create(); 
page.onResourceRequested = function (request) { 
    requests.push('Request ' + JSON.stringify(request, undefined, 4)); 
}; 
page.onResourceReceived = function (response) { 
    received.push('Receive ' + JSON.stringify(response, undefined, 4)); 
}; 
page.open(url);"); 

Sonra (aynı sayfada hala varsa) istekleri almaya:

browser.execute_script("function(){return requests }()"); 

ve alınan bağlantıları:

browser.execute_script("function(){return received}");