https login request - selenium webdriver

自古美人都是妖i 提交于 2021-02-11 17:55:35

问题


I was trying to access a https login url to login to a page and do my actions, but unable to do the same.

These are my observations.

When I hit the actual url, internally its leading to another url having JSESSION ID appended to it and then loading the requested page [now actual url formed].

Steps :

  • The actual url is like : https:/abcd.xyz.com:7443/abcd/Web/Admin

  • when I hit the above url driver.get("https:/abcd.xyz.com:7443/abcd/Web/Admin"); and when the test is running it appended Jsession id to another url, it looks like below, https:/abcd.xyz.com:7443/abcd/loginAsGuest.jsp;jsessionid=z712Ty0Rn0BHLTH6Q2Q02cBj233L0JHwNhy7vxW9ntNZDbLJLxQT!-840704556

  • Then actual url is formed [https://abcd.xyz.com:7443/abcd/Web/Admin] with the page loaded.

Here my problem is, my script is not proceeding from there and getting NoSuchElementFound exception due to which am not able to login to the page.

Any help in resolving the above issue will be very much useful.

My Webdriver code looks like :

FirefoxProfile profile = new FirefoxProfile();
profile.setAssumeUntrustedCertificateIssuer(false);
WebDriver driver = new FirefoxDriver();
driver.get("https://abcd.xyz.com:7443/abcd/Web/Admin");
WebElement uname = driver.findElement(By.name("username"));
WebElement pwd = driver.findElement(By.name("password"));

log shows something like this :

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"name","selector":"username"}

Any help in resolving the above issue will be very much useful.

Thanks,
-Anil 09566212889


回答1:


I think it will be useful for you...

FirefoxDriver Driver=new FirefoxDriver();
Driver.get("http://www.gmail.com");
Thread.sleep(1000);
Driver.findElement(By.id("Email")).sendKeys("xx");
Driver.findElement(By.id("Passwd")).sendKeys("xx");
Driver.findElement(By.id("signIn")).click();
Thread.sleep(10000);



回答2:


I'm not sure if this will help, but I've used this method a few times. You need to form your get request with the login information you want to use like username:password@url.com. I can't remember where I saw to do this, but I'll try to dig it up.

In Python it would look like the following:

browser = webdriver.Firefox()
browser.get("https://username:password@192.168.1.1")


来源:https://stackoverflow.com/questions/22479413/https-login-request-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!