mkoehnke / WKZombie

WKZombie is a Swift framework for iOS/OSX to navigate within websites and collect data without the need of User Interface or API, also known as Headless browser. It can be used to run automated tests / snapshots and manipulate websites using Javascript.
MIT License
1.17k stars 100 forks source link

Submit form doesn't work #76

Open Wiingaard opened 6 years ago

Wiingaard commented 6 years ago

Hey, I'm planning to use WKZombie in an upcoming project. I'm trying to login to a website, by setting the value attributes of some input elements and submit a form. I Have experience as an iOS developer, but I'm quite new to the web development (HTML/CSS/Javascript), so maybe I'm misunderstanding something. I'm using the same process as the WKZombie Demo Application.

let action = open(loginUrl)
    >>* get(by: SearchType.id("m_Content_username2"))
    >>> setAttribute("value", value: credentials.username)
    >>* get(by: SearchType.id("password2"))
    >>> setAttribute("value", value: credentials.password)
    >>* get(by: SearchType.id("aspnetForm"))
    >>> submit(then: PostAction.wait(3.0))
    >>* get(by: SearchType.id("s_m_HeaderContent_picctrlthumbimage"))

action.start { (result) in
    print(result)
}

This gives me the following Log:

REQUEST
https://www.lectio.dk/lectio/163/login.aspx
[....]

SCRIPT
getElementByXpath("//*[@id='m_Content_username2']").setAttribute("value", "xxx"); document.documentElement.outerHTML;
[]

SCRIPT
getElementByXpath("//*[@id='password2']").setAttribute("value", "yyy"); document.documentElement.outerHTML;
[]

SCRIPT
document.getElementById('aspnetForm').submit();
[..................................]

It find all elements and sets the right attributes. When it's has submitted the form and waited for 3 seconds, it can't find the last element. When looking at the snapshots, I see that the attributes get set right, but on the last screenshot I see that the browser is still on the login page, with the password reset. I sure it's the right credentials. It seems that the form isn't submitted right. The printet result is "Element Not Found". Here is the HTML of the form:

<form method="post" action="./login.aspx" onsubmit="javascript:return WebForm_OnSubmit();" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'm_defaultformbtn')" id="aspnetForm" class="ls-master-container2" autocomplete="off">
<!— Lots of HTML and stuff —>
</form>

I've also tried:

This might not be an issue with WKZombie, but any clues would be much appreciated!! :) Great work with this project 👍

MasterSwift commented 6 years ago

Have you figured this out @Wiingaard ? If you are working with a website built with asp , it may be the cause of the error. check https://github.com/dejanstojanovic/MVC-Honeypot . let me know if you find a solution!