문제

I am trying to automate my test cases using selenium webdriver in java. It involves Basic Authentication Dialogs. For making IE, Chrome, FF Compatible using kind of same approach I have to use AutoIT I am done with IE and FF but for Chrome it is not working. I am using AutoIT Window Info tool for finding out Class and Control Name. But Chrome is pretty different in that case can anyone help?

Here is code for working IE and FF

 $classForBasicAuthenticationWindow = "[CLASS:#32770]"
 $username = "XXXXXX"
 $password = "XXXXXX"

 WinWait($classForBasicAuthenticationWindow,"",120)
 If WinExists($classForBasicAuthenticationWindow) Then
    WinActivate($classForBasicAuthenticationWindow)
    Send($username)
    Send("{TAB}")
    Send($password & "{Enter}")   
  EndIf

It is similar for FF, The above is for IE

For Chrome I have written this so far if you consider the window info tool you will understand that the popup is not a different window in case of chrome. So it become a bit complicated. Anyways here is what I have tried :

$classForBasicAuthenticationWindow = "[CLASS:Chrome_WidgetWin_1]"
$username = "XXXXX"
$password = "XXXXX"

WinWait($classForBasicAuthenticationWindow,"",120)
If WinExists($classForBasicAuthenticationWindow) Then
WinActivate($classForBasicAuthenticationWindow)
While 1
   $isAuthenticationRequiredVisible = ControlGetHandle($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]")
  If $isAuthenticationRequiredVisible <> "" Then 
     MsgBox($isAuthenticationRequiredVisible)
     ExitLoop
  EndIf
WEnd
ControlSend($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]", $username)
EndIf
도움이 되었습니까?

해결책

Why are you not opening your URL as so (by passing the login credentials in the URL)

@driver.get "#{username}:#{password}@#{URL}"

an example

@driver.get "user:pass@my.domain.com"

다른 팁

ControlSend method takes window Title not the class of the window. So try giving window Title as it appears in Autoit Window Info Tool.

The code given below worked for me.

$titleForBasicAuthenticationWindow = "Window Title As Given in Window Info Tool"
$username = "XXXXX"
$password = "XXXXX"

WinWait($classForBasicAuthenticationWindow,"",120)
If WinExists($classForBasicAuthenticationWindow) Then
 WinActivate($classForBasicAuthenticationWindow)
 ControlSend($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]", $username)
EndIf

For chrome i tried everything, the best way to enter credentials in basic http authentication popup is through AutoIT. you just need to add sleep(25000) in the beginning of the script. make sure that chrome is able to open that popup within 25 sec. if not then increase the sleep time.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top