doutan1875 2017-01-23 12:09
浏览 319

如何在Selenium WebDriver中打开url之前在PHP Facebook WebDriver中添加cookie?

My Site is proxy protected with in alert box authentication. I have try this eg: http://username:password@xyz.com but not working in my case. Developers added cookie on website when I am going to add cookies before URL opens getting error:

InvalidCookieDomainError is not defined.

Is there any other way to bypass proxy authentications?

Is it possible to add cookie without open domain?

  • 写回答

1条回答 默认 最新

  • duanjia2772 2017-01-23 15:06
    关注

    Okay Raza, if your aim is to check for an alert and accept it if it exists (as you mentioned that some pages are showing you the alert and some not); try using the following method see if this solves your problem:

    public boolean isAlertPresent() throws InterruptedException {       
    
            try {
                for(int i=1; i<3; i++){
                TimeUnit.SECONDS.sleep(3);
                getDriver().switchTo().alert();
                System.out.printf("%n*** An alert was present ***");
                alertPresent=true;                 
                }               
                catch (NoAlertPresentException e) {
                System.out.printf("%n*** An alert was not present ***");
                alertPresent=false;         
                }   
    
            return alertPresent;
        }
    

    Now depending on whether the alert was present or not you can direct your flow, this is how you accept the alert (yes, ok, continue):

    if (alertPresent==true){
     driver.switchTo().alert().accept();
     System.out.println("Successfully accepted an alert!");
     }
     else{System.out.println("Couldn't locate an alert!");} 
    

    Hope the above solves it for you; if not, no worries, post a msg below and we will see what we can do.

    Best of luck!

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?