This article is participating in Python Theme Month. See the link to the event for more details

doubt

  • Is that even a question?
Why do you have to break the captcha, the slider captcha login?Copy the code
  • First of all, I do not think this is a problem, or technical difficulties < not difficult, coding solutions, the whole network can be found >!!
In front of the tester, to be able to achieve this problem, is a reflection of ability? No, the purpose is to test, not to spend a lot of time 'manufacturing' the problem.Copy the code

plan

Plan a
It is said that the purpose of testing is not to spend a lot of time 'creating' problems, so why not communicate and get the techs to kill the feature and everyone will be happy?Copy the code
Scheme 2
One of the same scheme is not much to say, nothing more than to kill and let the function invalid; The following solution is called using cookies to bypass login: roughly means to manually log in, get the browser saved login cookie information < cookies >, and then put into the code to achieve the operation.Copy the code
Plan 3
  • IT’s just sule, no way, one of the things that most IT people do, nobody wants to talk about IT, so let’s do IT in code.

Implementation Plan 2

  • Prepare the Python+ Selenium + Eclipse local development environment
  • Testers are required to know some basic code. I’ll use Python as an example:
The train of thought has been talked about above, say do doCopy the code
  • Write the basic code
from selenium import webdriver
from time import sleep

# Create object
driver=webdriver.Chrome()
driver.implicitly_wait(30)
driver.maximize_window()

# Open the Nugget website
driver.get("https://juejin.cn/")
# Click to write
driver.find_element_by_xpath("//button[@class='add-btn']").click()
To show that the truncated graph is generated by executing the script, enter the data first
driver.find_element_by_name("mobile").send_keys("I'm the result of executing a script.")
# Because there is no login, there will inevitably be a login box, in order to save the evidence, first cut a picture
driver.save_screenshot("login.png")
sleep(1)

# Custom disable driver
driver.quit()
Copy the code
  • Take a look at the screenshot (to prove it, the author is also painstakingly)

  • Now it’s time to manually log in and take the cookie information down
So once F12 is on, nothing's a problem you can take a cookie from the application's cookie, you can take a cookie from any Juejin request header on the network, rightCopy the code

  • Once you get it, you can add it in your code
from selenium import webdriver
from time import sleep

# Create object
option=webdriver.ChromeOptions()
option.add_argument('--start-maximized')
driver=webdriver.Chrome(options=option)
driver.implicitly_wait(30)

Open the nugget address
driver.get("https://juejin.cn/")

# This is a manually captured cookie; The browser's F12 cookie, the entire portion of the cookie, or the cookie of any mining request by the Network
cookie=[{'domain': 'juejin.cn'.'expiry': 1657263267.'httpOnly': False.'name': 'tt_scid'.'path': '/'.'secure': False.'value': 'dBWWtxewU2323E3h2BNLVLk4.JlsQESlaKLE0-WhIuDJIuOK1D2D323Sug819a'}, {'domain': '.juejin.cn'.'expiry': 1633503267.'httpOnly': False.'name': 'MONITOR_WEB_ID'.'path': '/'.'secure': False.'value': 'fe97cd76-9ab6-49e2-96f8-598566df70ef'}, {'domain': '.juejin.cn'.'expiry': 16326095266.'httpOnly': True.'name': 'n_mh'.'path': '/'.'secure': False.'value': 'd5W33G2X2hXeGu0Ggg-fNK-ov5_S_2pHUYxNwUIs_U'}, {'domain': '.juejin.cn'.'expiry': 1630911266.'httpOnly': True.'name': 'sessionid_ss'.'path': '/'.'sameSite': 'None'.'secure': True.'value': '26526275e97c23a531657989dd922d0f9c3'}, {'domain': '.juejin.cn'.'expiry': 1630911266.'httpOnly': True.'name': 'sessionid'.'path': '/'.'secure': False.'value': '2652675e293365279289dd922d0f9c3'}, {'domain': '.juejin.cn'.'expiry': 1630911266.'httpOnly': True.'name': 'sid_tt'.'path': '/'.'secure': False.'value': '2652675e97c3a52333d92d0f9c3'}, {'domain': '.juejin.cn'.'expiry': 1630911266.'httpOnly': True.'name': 'uid_tt'.'path': '/'.'secure': False.'value': '69ee1a6b20c8c7ccf0d11e4290b1ed1'}, {'domain': '.juejin.cn'.'expiry': 1630911266.'httpOnly': True.'name': 'uid_tt_ss'.'path': '/'.'sameSite': 'None'.'secure': True.'value': '69ee1a6b0c8c7ccf0d13574e490b1ed1'}, {'domain': '.juejin.cn'.'expiry': 1656831266.'httpOnly': True.'name': 'sid_guard'.'path': '/'.'secure': False.'value': '26526752e97c3a531657989d229c3%7C1625727266%7C15184000%7CMon%2C+06-Sep-2021+062%3A54%3A26+GMT'}, {'domain': '.juejin.cn'.'expiry': 1630911256.'httpOnly': False.'name': 'passport_csrf_token_default'.'path': '/'.'secure': False.'value': '2dc015e17fd727f271c422f65b112b83ec'}, {'domain': '.juejin.cn'.'expiry': 1625813667.'httpOnly': False.'name': '_gid'.'path': '/'.'secure': False.'value': 'GA1.2.3134962563.1625727249'}, {'domain': '.juejin.cn'.'expiry': 1688799267.'httpOnly': False.'name': '_ga'.'path': '/'.'secure': False.'value': 'GA1.2.86874112136.1625727249'}, {'domain': 'juejin.cn'.'httpOnly': False.'name': 's_v_web_id'.'path': '/'.'secure': False.'value': 'verify_kquk17pb_m0kzTiE8_XhZj_421My_97SN_QPs7c3mtpnxE'}, {'domain': '.juejin.cn'.'expiry': 16309121256.'httpOnly': False.'name': 'passport_csrf_token'.'path': '/'.'sameSite': 'None'.'secure': True.'value': '2dc015e17fd77f21712c422f65b11b83ec'}, {'domain': 'juejin.cn'.'expiry': 1657263248.'httpOnly': False.'name': 'ttcid'.'path': '/'.'secure': False.'value': 'b0165937cfa542387940da1d7a29b5290452'}]

# Traverse to add cookie
for cook in cookie:
    driver.add_cookie(cook)

# Refresh the current window
driver.refresh()
    
# Click to write
driver.find_element_by_xpath("//button[@class='add-btn']").click()

To show that the truncated graph is generated by executing the script, enter the data first
# driver.find_element_by_name("mobile").send_keys(" I am the result of script execution ")
# Because there is no login, there will inevitably be a login box, in order to save the evidence, first cut a picture
# driver.save_screenshot("login.png")

# to write the title
driver.find_element_by_xpath("//input[@class='title-input title-input']").send_keys("I am the title")
sleep(1)
# write content
ele=driver.find_element_by_xpath("//div[@class='CodeMirror cm-s-default CodeMirror-wrap']")
driver.execute_script("arguments[0].CodeMirror.setValue(arguments[1]);", ele, "Write something 123")
 
sleep(1)
Click on the draft box
driver.find_element_by_xpath("/ / button [contains (text (), 'the grass')]").click()
# View draft box screenshots
sleep(3)
# Custom disable driver
driver.quit()
Copy the code
  • Then you can see what you just typed in the draft box

conclusion

  • Can you use cookies for purposes you don’t know about?
And to tell you a secret, if a system does not do single device login, then its cookies can be N and not invalid.Copy the code