简体   繁体   中英

How to get CSRF Token and pass it into Selenium WebDriver with Java to automate login function for website preventing automation script

I am a novice in Selenium with Java. I have a tricky case that needs support from an expert. I am trying to automate an e-commerce site with Selenium WebDriver JAVA. As a manual, I login successfully with my registered credential. But when I run my automation script for this login function, the site prevents me from automating this by not generating the CSRF Token for my logging in a request. Every login script running with a validly registered credential, the "Invalid CSRF Token" message is displayed. I know that this site is preventing automation script for spam blocking. But this is my exercise test and I must pass this. So I post this for the support request that whether I bypass the CSRF Token in the login script for automating this smoothly?

Thank you for spending your time and reading my case.

You need to get the CSRF token value and set in request header to resolve this issue.

Please find Robot framework snap of the same issue,

${status} ${cookie_CSRF}= Run Keyword And Ignore Error Selenium2Library.Get Cookie Value X-CSRF Run Keyword If '${status}'=='PASS' Set Request Header X-CSRF ${cookie_CSRF}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM