如何使用PhantomJS查找Frame元素?

时间:2015-09-14 12:15:46

标签: java iframe selenium-webdriver phantomjs

我正在开发基于框架的网站。我正在使用硒2.47.1& PhantomJS 1.9.2。我写了自动化脚本&使用firefox驱动程序运行它,它完美地工作。我试图用帮助PhanthomJS驱动程序执行代码。但每当我尝试执行它时,它都会产生NoSuchFrameFoundException。我的脚本如下......

     let devID = "12345678-1234-1234-1234-123456789123"

 func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {

        if peripheral.identifier.UUIDString == devID
        {
            self.centralManager?.stopScan()
            self.myperipheral = peripheral
            self.myperipheral?.delegate = self
            self.centralManager?.connectPeripheral(peripheral, options: nil)
        }
    }


    func centralManager(central: CBCentralManager!, didConnectPeripheral peripheral: CBPeripheral!) {

        if peripheral.identifier.UUIDString == devID
        {
            if peripheral.state == CBPeripheralState.Connected
            {
                var uid : CBUUID = CBUUID(string: "FF70")
                self.myperipheral = peripheral
                self.myperipheral?.delegate = self
                self.myperipheral?.discoverServices([CBUUID(string: peripheral.identifier.UUIDString)])
            }
        }
    }

 func centralManager(central: CBCentralManager!, didDisconnectPeripheral peripheral: CBPeripheral!, error: NSError!) {
            println("Disconnected!== \(error)")
    }


    func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!) {

            if let servicePeripherals = peripheral.services as? [CBService]
            {
                for servicePeripheral in servicePeripherals
                {
                    peripheral.discoverCharacteristics([servicePeripheral.UUID], forService: servicePeripheral)
                }
            }
    }



    func peripheral(peripheral: CBPeripheral!, didDiscoverCharacteristicsForService service: CBService!, error: NSError!) {

        if let charactericsArr = service.characteristics  as? [CBCharacteristic]
        {
            for charactericsx in charactericsArr
            {
                peripheral.setNotifyValue(true, forCharacteristic: charactericsx)

                if charactericsx.UUID.UUIDString == devID{
                    var parameter = NSInteger(1)
                    let data = NSData(bytes: &parameter, length: 1)
                    peripheral.writeValue(data, forCharacteristic: charactericsx, type: CBCharacteristicWriteType.WithResponse)
                }

                if charactericsx.UUID.UUIDString == "FF70" || charactericsx.UUID.UUIDString == "FF71"{
                    var parameter = NSInteger(1)
                    let data = NSData(bytes: &parameter, length: 1)
                    peripheral.writeValue(data, forCharacteristic: charactericsx, type: CBCharacteristicWriteType.WithResponse)
                    }
                peripheral.readValueForCharacteristic(charactericsx)
            }
        }

    }

    func readValueForCharacteristic(Charactersic: CBCharacteristic!){
        println("character == \(Charactersic)")
    }


    func peripheral(peripheral: CBPeripheral!, didUpdateNotificationStateForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {

        if ((error) != nil) {
            println("Error discovering service: \(error.localizedDescription)")
            return;
        }

        println("description: \(characteristic.description), descriptors: \(characteristic.descriptors), properties: \(characteristic.properties), service :\(characteristic.service), value:\(characteristic.value)")

        if (characteristic.isNotifying) {
            peripheral.readValueForCharacteristic(characteristic)
        }
    }

以上代码给出以下异常..

public class iFrame {
public String baseUrl = "https://test5.icoreemr.com/interface/login/login.php";
public WebDriver cd;
String scenarioName = "Sheet1";
ExcelLibrary ex = new ExcelLibrary();

@BeforeTest
public void SetBaseUrl() {
    Capabilities caps = new DesiredCapabilities();
    ((DesiredCapabilities) caps).setJavascriptEnabled(true);                
    ((DesiredCapabilities) caps).setCapability(
            PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            "C:\\Users\\Probe7\\Downloads\\phantomjs-1.9.2-windows\\phantomjs.exe"
        );
    this.cd = new PhantomJSDriver(caps);
    cd.get(baseUrl);
    cd.manage().window().maximize();
}

 @Test(priority = 0)
/* Login into the Application */
public void Login()  {
     cd.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
     cd.switchTo().frame("Login");
     System.out.println("Control Moved to Login Frame");
     String UserName = ex.getExcelValue(scenarioName, 2, 4);
     cd.findElement(By.xpath("//body/center/form/table/tbody/tr/td/div/div[2]/table/tbody/tr[1]/td[2]/input")).sendKeys(UserName); 
} 

尽管同样的脚本在firefox驱动程序中完美运行,但在PhantomJS中却没有。 请问我出了什么问题?我正在调查这近一天,但没有找到任何解决方案..请帮我这个? 在此先感谢...

0 个答案:

没有答案