0

How are sites protected from being log in by Selenium web driver?

At the same time you can enter the log in form manually and all other part of selenium code will work, how is that achieved?

Is it possible to log in into such site by Selenium web driver?

<!-- login form -->
<form action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
<script type="text/javascript" src="clientscript/vbulletin_md5.js?v=387"></script>
<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td class="smallfont" style="white-space: nowrap;"><label for="navbar_username">Имя</label></td>
<td><input type="text" class="bginput" style="font-size: 11px" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="Имя" onfocus="if (this.value == 'Имя') this.value = '';" /></td>
<td class="smallfont" nowrap="nowrap"><label for="cb_cookieuser_navbar"><input type="checkbox" name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" />Запомнить?</label></td>
</tr>
<tr>
<td class="smallfont"><label for="navbar_password">Пароль</label></td>
<td><input type="password" class="bginput" style="font-size: 11px" name="vb_login_password" id="navbar_password" size="10" tabindex="102" /></td>
<td><input type="submit" class="button" value="Вход" tabindex="104" title="Введите ваше имя пользователя и пароль, чтобы войти, или нажмите кнопку 'Регистрация', чтобы зарегистрироваться." accesskey="s" /></td>
</tr>
</table>
<input type="hidden" name="s" value="" />
<input type="hidden" name="securitytoken" value="1494435076-6acf057fb2e17e28bd5679c57501a85f896b4310" />
<input type="hidden" name="do" value="login" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
</form>
<!-- / login form -->
Chanda Korat
  • 2,453
  • 2
  • 19
  • 23
thinker
  • 402
  • 1
  • 6
  • 15

3 Answers3

1

You can log in with Selenium in two ways:

  1. Via filling out a form on the login page. This involves finding username and password elements and inputting information for a test user you have created in a test database.

  2. Login on the backend of your system programatically rather than using the UI. This will still require a username and password, should just work in a test environment, and the syntax depends upon what kind of authentication module you are using.

Julie
  • 1,941
  • 3
  • 17
  • 30
1

How are sites protected from being log in by Selenium web driver?

I haven't seen any site that can differentiate between human and Selenium webdriver accessing the webpage. There may be some, I am not sure. See this.

However, it is difficult to automate tasks for site for which id, classname, name of html tags changes on each reload. Google plus is one such example, there are many. For sites like Bet365 it is difficult to automate tasks because there are real time reloads.

To differentiate between bot and humans CAPTCHA is used by websites.


At the same time you can enter the log in form manualy and all other part of selenium code will work, how is that achived?

Yes, it can be achieved. You can make your program wait for a duration and enter your information (eg: username, password). Then you can perform operations like click or select using your script. But your browser should be opened using Webdriver.

To make your program wait you can use Thread.sleep(int), but you can go for WebDriverWait for better results.

Here the tough job will be deciding the wait time, because every human won't have same speed for entering values.


As suggested by ElementCR, sendkeys("value") is better than manual input.

Community
  • 1
  • 1
r_D
  • 578
  • 1
  • 7
  • 16
0

After looking for some examples I found this reference. How to valid a login page using Java and Selenium WebDriver?

Be sure to switch up the findElement(By.(Identifier)).

Not sure if this will provide immediate results, but this is where I would start.

Good luck.

@Before
public void setup() throws MalformedURLException, UnknownHostException{
driver = new HtmlUnitDriver(true);
driver.get(System.getProperty("login.url"));
}

@Test
public void login(){
driver.findElement(By.name("vb_login_username")).sendKeys("login");
driver.findElement(By.name("vb_login_password")).sendKeys("password");     
driver.findElement(By.type("submit")).click();
}
Community
  • 1
  • 1
ElementCR
  • 178
  • 12
  • I cannot at the moment, but later in the day I can give it a shot. Do you have valid test cases that I can use? If you send me a private message I can see what is possible. – ElementCR May 10 '17 at 18:39