├── .DS_Store
├── .idea
├── DevAuto.iml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── LICENSE
├── README.md
├── datatest_demo
└── readme.md
├── debug_sample
└── print_debug.py
├── img
├── python_cmd.png
├── python_download.png
├── 公众号.jpg
└── 直播室.png
├── pig.py
├── python3_sample
├── __pycache__
│ └── test_data_zh_CN.cpython-36.pyc
├── faker_create_provider.py
├── faker_providers_basic.py
├── faker_zh_CN.py
├── readme.md
├── test_data_name.py
└── test_data_zh_CN.py
├── selenium_python
├── 1
│ └── 下载地址.md
├── 2
│ ├── 1.1 Python3安装.md
│ ├── 2.1_base_sample.py
│ ├── 2.2_unit_sample.py
│ └── 2.3_remote_sample.py
├── 3
│ ├── 3.10_find_ele_by_css.py
│ ├── 3.11_find_child_ele.py
│ ├── 3.12_find_multiple_elements.py
│ ├── 3.2_start_browser.py
│ ├── 3.3_find_ele_by_id.py
│ ├── 3.4_find_ele_by_name.py
│ ├── 3.5_find_ele_by_link_text.py
│ ├── 3.6_find_ele_by_partial_link_text.py
│ ├── 3.7_find_ele_by_xpath.py
│ ├── 3.8_find_ele_by_tag_name.py
│ └── 3.9_find_ele_by_class_name.py
├── 4
│ ├── 4.1.1_input_text.py
│ ├── 4.1.2_input_text.py
│ ├── 4.2.1_mouse_click.py
│ ├── 4.2.2_mouse_doubleclick.py
│ ├── 4.2.3_mouse_rightclick.py
│ ├── 4.2.4_mouse_move.py
│ ├── 4.2.5_mouse_hold_on.py
│ ├── 4.2.6_mouse_drag_and_drop.py
│ ├── 4.3.1_alert_win.py
│ ├── 4.3.2_confirm_win.py
│ ├── 4.3.3_prompt_win.py
│ ├── 4.3.4_select.py
│ ├── 4.3.5_multi_select.py
│ ├── 4.3.6_switch_windows.py
│ ├── 4.3.7_switch_frame.py
│ ├── 4.3.8_control_browser.py
│ ├── 4.3.9_manage_cookies.py
│ ├── demo.html
│ └── demo.html.zip
├── 5
│ ├── 5.10_frame_to_be_available_and_switch_to_it.py
│ ├── 5.11_invisibility_of_element_located.py
│ ├── 5.1_implicitly_wait.py
│ ├── 5.2_title_is.py
│ ├── 5.3_title_contains.py
│ ├── 5.4_presence_of_element_located.py
│ ├── 5.5_visibility_of_element_located.py
│ ├── 5.6_visibility_of.py
│ ├── 5.7_presence_of_all_elements_located.py
│ ├── 5.8_text_to_be_present_in_element.py
│ └── 5.9_text_to_be_present_in_element_value.py
└── .DS_Store
├── test_pipeline
└── unittest_demo
└── readme.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/.DS_Store
--------------------------------------------------------------------------------
/.idea/DevAuto.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
156 |
157 |
158 |
159 | MAX_RETRIES
160 | 川AD34RF
161 | switch_to
162 | alert
163 | confirm
164 |
165 |
166 | confirm
167 | prompt
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 | 1542007332055
363 |
364 |
365 | 1542007332055
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DevAuto
2 |
3 | Python测试开发系列代码集
4 |
5 | 我的公众号
6 |
7 | 
8 |
9 |
--------------------------------------------------------------------------------
/datatest_demo/readme.md:
--------------------------------------------------------------------------------
1 | 数据测试demo
--------------------------------------------------------------------------------
/debug_sample/print_debug.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | """
6 |
7 | 公众号: 开源优测
8 |
9 | Email: lymking@foxmail.com
10 |
11 | """
12 |
13 | import sys
14 |
15 |
16 | # 定义print输出级别, 用于控制print输出
17 | # 优先级 DEBUG > INFO > WARNING > ERROR
18 | class Print:
19 | DEBUG = 0
20 | INFO = 1
21 | WARNING = 2
22 | ERROR = 3
23 | PRINT_TIP = {DEBUG: "Debug", INFO: "Info", WARNING: "Warn", ERROR: "Error"}
24 |
25 |
26 | # 全局print控制标志
27 | PRINT_LEVEL = Print.ERROR
28 |
29 |
30 | # 自定义print输出
31 | # msg - 输出内容
32 | # level - 输出级别控制
33 | def print_console(msg, level=Print.INFO):
34 | filename = sys._getframe().f_code.co_filename
35 | func = sys._getframe().f_code.co_name
36 | line = sys._getframe().f_lineno
37 | if level >= PRINT_LEVEL:
38 | print("In File: %s, Function: %s @line: %s %s: %s" % (filename, func, line, Print.PRINT_TIP[level], msg))
39 |
40 |
41 | # 测试print_console
42 | def test_print_console():
43 | print_console("这是debug输出...", Print.DEBUG)
44 |
45 | print_console("这是info输出....", Print.INFO)
46 |
47 | print_console("这是warning输出...", Print.WARNING)
48 |
49 | print_console("这是error输出", Print.ERROR)
50 |
51 | print("---" * 10)
52 |
53 |
54 | if __name__ == "__main__":
55 | print("print输出示例")
56 |
57 | # 设置输出为DEBUG级别
58 | PRINT_LEVEL = Print.DEBUG
59 | test_print_console()
60 |
61 | # 设置输出为INFO级别
62 | PRINT_LEVEL = Print.INFO
63 | test_print_console()
64 |
65 | # 设置输出为Warning级别
66 | PRINT_LEVEL = Print.WARNING
67 | test_print_console()
68 |
69 | # 设置输出为ERROR级别
70 | PRINT_LEVEL = Print.ERROR
71 | test_print_console()
72 |
73 |
--------------------------------------------------------------------------------
/img/python_cmd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/img/python_cmd.png
--------------------------------------------------------------------------------
/img/python_download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/img/python_download.png
--------------------------------------------------------------------------------
/img/公众号.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/img/公众号.jpg
--------------------------------------------------------------------------------
/img/直播室.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/img/直播室.png
--------------------------------------------------------------------------------
/pig.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | import turtle as t
3 | # 绘制小猪佩奇
4 | # =======================================
5 |
6 | t.pensize(4)
7 | t.hideturtle()
8 | t.colormode(255)
9 | t.color((255, 155, 192), "pink")
10 | t.setup(840, 500)
11 | t.speed(10)
12 |
13 | # 鼻子
14 | t.pu()
15 | t.goto(-100,100)
16 | t.pd()
17 | t.seth(-30)
18 | t.begin_fill()
19 | a = 0.4
20 | for i in range(120):
21 | if 0 <= i < 30 or 60 <= i < 90:
22 | a = a+0.08
23 | t.lt(3) # 向左转3度
24 | t.fd(a) # 向前走a的步长
25 | else:
26 | a = a-0.08
27 | t.lt(3)
28 | t.fd(a)
29 | t.end_fill()
30 |
31 | t.pu()
32 | t.seth(90)
33 | t.fd(25)
34 | t.seth(0)
35 | t.fd(10)
36 | t.pd()
37 | t.pencolor(255, 155, 192)
38 | t.seth(10)
39 | t.begin_fill()
40 | t.circle(5)
41 | t.color(160, 82, 45)
42 | t.end_fill()
43 |
44 | t.pu()
45 | t.seth(0)
46 | t.fd(20)
47 | t.pd()
48 | t.pencolor(255, 155, 192)
49 | t.seth(10)
50 | t.begin_fill()
51 | t.circle(5)
52 | t.color(160, 82, 45)
53 | t.end_fill()
54 |
55 | # 头
56 | t.color((255, 155, 192), "pink")
57 | t.pu()
58 | t.seth(90)
59 | t.fd(41)
60 | t.seth(0)
61 | t.fd(0)
62 | t.pd()
63 | t.begin_fill()
64 | t.seth(180)
65 | t.circle(300, -30)
66 | t.circle(100, -60)
67 | t.circle(80, -100)
68 | t.circle(150, -20)
69 | t.circle(60, -95)
70 | t.seth(161)
71 | t.circle(-300, 15)
72 | t.pu()
73 | t.goto(-100, 100)
74 | t.pd()
75 | t.seth(-30)
76 | a = 0.4
77 | for i in range(60):
78 | if 0 <= i < 30 or 60 <= i <90:
79 | a = a+0.08
80 | t.lt(3) # 向左转3度
81 | t.fd(a) # 向前走a的步长
82 | else:
83 | a = a-0.08
84 | t.lt(3)
85 | t.fd(a)
86 | t.end_fill()
87 |
88 | # 耳朵
89 | t.color((255, 155, 192), "pink")
90 | t.pu()
91 | t.seth(90)
92 | t.fd(-7)
93 | t.seth(0)
94 | t.fd(70)
95 | t.pd()
96 | t.begin_fill()
97 | t.seth(100)
98 | t.circle(-50, 50)
99 | t.circle(-10, 120)
100 | t.circle(-50, 54)
101 | t.end_fill()
102 |
103 | t.pu()
104 | t.seth(90)
105 | t.fd(-12)
106 | t.seth(0)
107 | t.fd(30)
108 | t.pd()
109 | t.begin_fill()
110 | t.seth(100)
111 | t.circle(-50, 50)
112 | t.circle(-10, 120)
113 | t.circle(-50, 56)
114 | t.end_fill()
115 |
116 | #眼睛
117 | t.color((255, 155, 192), "white")
118 | t.pu()
119 | t.seth(90)
120 | t.fd(-20)
121 | t.seth(0)
122 | t.fd(-95)
123 | t.pd()
124 | t.begin_fill()
125 | t.circle(15)
126 | t.end_fill()
127 |
128 | t.color("black")
129 | t.pu()
130 | t.seth(90)
131 | t.fd(12)
132 | t.seth(0)
133 | t.fd(-3)
134 | t.pd()
135 | t.begin_fill()
136 | t.circle(3)
137 | t.end_fill()
138 |
139 | t.color((255, 155, 192), "white")
140 | t.pu()
141 | t.seth(90)
142 | t.fd(-25)
143 | t.seth(0)
144 | t.fd(40)
145 | t.pd()
146 | t.begin_fill()
147 | t.circle(15)
148 | t.end_fill()
149 |
150 | t.color("black")
151 | t.pu()
152 | t.seth(90)
153 | t.fd(12)
154 | t.seth(0)
155 | t.fd(-3)
156 | t.pd()
157 | t.begin_fill()
158 | t.circle(3)
159 | t.end_fill()
160 |
161 | # 腮
162 | t.color((255, 155, 192))
163 | t.pu()
164 | t.seth(90)
165 | t.fd(-95)
166 | t.seth(0)
167 | t.fd(65)
168 | t.pd()
169 | t.begin_fill()
170 | t.circle(30)
171 | t.end_fill()
172 |
173 | # 嘴
174 | t.color(239, 69, 19)
175 | t.pu()
176 | t.seth(90)
177 | t.fd(15)
178 | t.seth(0)
179 | t.fd(-100)
180 | t.pd()
181 | t.seth(-80)
182 | t.circle(30, 40)
183 | t.circle(40, 80)
184 |
185 | # 身体
186 | t.color("red", (255, 99, 71))
187 | t.pu()
188 | t.seth(90)
189 | t.fd(-20)
190 | t.seth(0)
191 | t.fd(-78)
192 | t.pd()
193 | t.begin_fill()
194 | t.seth(-130)
195 | t.circle(100,10)
196 | t.circle(300,30)
197 | t.seth(0)
198 | t.fd(230)
199 | t.seth(90)
200 | t.circle(300,30)
201 | t.circle(100,3)
202 | t.color((255,155,192),(255,100,100))
203 | t.seth(-135)
204 | t.circle(-80,63)
205 | t.circle(-150,24)
206 | t.end_fill()
207 |
208 | # 手
209 | t.color((255,155,192))
210 | t.pu()
211 | t.seth(90)
212 | t.fd(-40)
213 | t.seth(0)
214 | t.fd(-27)
215 | t.pd()
216 | t.seth(-160)
217 | t.circle(300,15)
218 | t.pu()
219 | t.seth(90)
220 | t.fd(15)
221 | t.seth(0)
222 | t.fd(0)
223 | t.pd()
224 | t.seth(-10)
225 | t.circle(-20,90)
226 |
227 | t.pu()
228 | t.seth(90)
229 | t.fd(30)
230 | t.seth(0)
231 | t.fd(237)
232 | t.pd()
233 | t.seth(-20)
234 | t.circle(-300,15)
235 | t.pu()
236 | t.seth(90)
237 | t.fd(20)
238 | t.seth(0)
239 | t.fd(0)
240 | t.pd()
241 | t.seth(-170)
242 | t.circle(20,90)
243 |
244 | # 脚
245 | t.pensize(10)
246 | t.color((240,128,128))
247 | t.pu()
248 | t.seth(90)
249 | t.fd(-75)
250 | t.seth(0)
251 | t.fd(-180)
252 | t.pd()
253 | t.seth(-90)
254 | t.fd(40)
255 | t.seth(-180)
256 | t.color("black")
257 | t.pensize(15)
258 | t.fd(20)
259 |
260 | t.pensize(10)
261 | t.color((240, 128, 128))
262 | t.pu()
263 | t.seth(90)
264 | t.fd(40)
265 | t.seth(0)
266 | t.fd(90)
267 | t.pd()
268 | t.seth(-90)
269 | t.fd(40)
270 | t.seth(-180)
271 | t.color("black")
272 | t.pensize(15)
273 | t.fd(20)
274 |
275 | # 尾巴
276 | t.pensize(4)
277 | t.color((255, 155, 192))
278 | t.pu()
279 | t.seth(90)
280 | t.fd(70)
281 | t.seth(0)
282 | t.fd(95)
283 | t.pd()
284 | t.seth(0)
285 | t.circle(70, 20)
286 | t.circle(10, 330)
287 | t.circle(70, 30)
288 | t.done()
289 |
--------------------------------------------------------------------------------
/python3_sample/__pycache__/test_data_zh_CN.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/python3_sample/__pycache__/test_data_zh_CN.cpython-36.pyc
--------------------------------------------------------------------------------
/python3_sample/faker_create_provider.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | """
7 | 实现一个简单的faker provider
8 | """
9 |
10 | from faker import Faker
11 |
12 |
13 | # 导入provider基类,我们的provider需要继承该类
14 | from faker.providers import BaseProvider
15 |
16 |
17 | # 创建一个我们的provider
18 | class MyProvider(BaseProvider):
19 | def my_name(self):
20 | return "DeepTest"
21 |
22 |
23 | if __name__ == "__main__":
24 | print("使用自定义Provider实例")
25 |
26 | fake = Faker('zh_CN')
27 |
28 | # 将自定义provider添加至fake
29 | fake.add_provider(MyProvider)
30 |
31 | # 调用自定义provider中方法,生成数据
32 | my_name = fake.my_name()
33 |
34 | print(my_name)
35 |
--------------------------------------------------------------------------------
/python3_sample/faker_providers_basic.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | """
6 | faker providers基本实例
7 | """
8 |
9 | from faker import Faker
10 |
11 | # 从providers中导入internet组件
12 | from faker.providers import internet
13 |
14 |
15 | if __name__ == "__main__":
16 | fake = Faker("zh_CN")
17 |
18 | # 添加provider组件
19 | fake.add_provider(internet)
20 |
21 | # 生成一个私有的ip
22 | ip = fake.ipv4_private()
23 |
24 | print(ip)
25 |
--------------------------------------------------------------------------------
/python3_sample/faker_zh_CN.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from faker import Faker
6 |
7 | """"
8 | 基于Faker生成不同测试数据实例
9 | """
10 |
11 |
12 | if __name__ == "__main__":
13 |
14 | # 创建faker实例,中文
15 | # 如果要生成其他语言,则将zh_CN改成对应的语言执行
16 | fake = Faker("zh_CN")
17 |
18 | print("------ 生成5个姓名-----")
19 | for _ in range(5):
20 | print(fake.name())
21 |
22 | print("\n------ 生成5个国家-----")
23 | for _ in range(5):
24 | print(fake.country())
25 |
26 | print("\n------ 生成5个条码-----")
27 | for _ in range(5):
28 | print(fake.ean8()) # 8位条形码
29 | print(fake.ean13()) # 13位条形码
30 |
31 | print("\n------ 生成5个颜色-----")
32 | for _ in range(5):
33 | print(fake.hex_color())
34 |
35 | print("\n------ 生成5个公司名-----")
36 | for _ in range(5):
37 | print(fake.company())
38 |
39 | print("\n------ 生成5个信用卡-----")
40 | for _ in range(5):
41 | print(fake.credit_card_number(card_type=None)) # 卡号
42 | print(fake.credit_card_provider(card_type=None)) # 卡的提供者
43 | print(fake.credit_card_security_code(card_type=None)) # 卡的安全密码
44 | print(fake.credit_card_expire()) # 卡的有效期
45 | print(fake.credit_card_full(card_type=None)) # 完整卡信息
46 | print("---" * 5)
47 |
48 |
49 | print("\n\n其他方法这里就不一一演示,请自信敲代码")
50 |
--------------------------------------------------------------------------------
/python3_sample/readme.md:
--------------------------------------------------------------------------------
1 | ## 说明
2 |
3 | 为Python3实例手把手系列端视频的代码实例集合
4 |
5 |
6 | 微信扫一扫关注直播室
7 |
8 | 
9 |
--------------------------------------------------------------------------------
/python3_sample/test_data_name.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | import random
7 |
8 | # 导入汉字生成函数
9 | from test_data_zh_CN import *
10 |
11 |
12 | """"
13 | 简单生成中文名
14 | """
15 |
16 | # 百家姓列表
17 | FIRST_NAME = ['赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许',
18 | '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦', '章',
19 | '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马', '苗', '凤', '花', '方', '俞', '任', '袁', '柳',
20 | '酆', '鲍', '史', '唐', '费', '廉', '岑', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬', '安', '常',
21 | '乐', '于', '时', '傅', '皮', '卞', '齐', '康', '伍', '余', '元', '卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹',
22 | '姚', '邵', '堪', '汪', '祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈', '宋', '茅', '庞',
23 | '熊', '纪', '舒', '屈', '项', '祝', '董', '梁']
24 |
25 |
26 | if __name__ == "__main__":
27 | # 随便生成下名字啦
28 |
29 | for _ in range(10):
30 | first = FIRST_NAME[random.randint(0, len(FIRST_NAME))]
31 | name = gbk2312_zh()
32 | print(first + name)
--------------------------------------------------------------------------------
/python3_sample/test_data_zh_CN.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | """
7 | 生成中文实例
8 | """
9 |
10 | import random
11 |
12 | # 直接基于unicode码生成
13 | # 在unicode码中,汉字范围是(0x4E00, 0x9FBF)
14 |
15 |
16 | def unicode_zh():
17 | # 随机生成一个汉字码
18 | zh = random.randint(0x4E00, 0x9FBF)
19 |
20 | # 转换下,返回
21 | return chr(zh)
22 |
23 |
24 | # 基于gbk2312码生成
25 | # 在gbk2312码中,字符的编码采用两个字节组合
26 | # 汉字第一个字节范围是(0xB0, 0xF7)
27 | # 汉字第二个字节范围是(0xA1, 0xFE)
28 |
29 |
30 | def gbk2312_zh():
31 | # 生成第一个字节
32 | first = random.randint(0xB0, 0xF7)
33 | # 生成第二个字节
34 | last = random.randint(0xA1, 0xFE)
35 |
36 | # 组合一下
37 | s = f'{first:x}{last:x}'
38 |
39 | # 转换成汉字
40 | zh = bytes.fromhex(s).decode('gb2312')
41 |
42 | # 返回
43 | return zh
44 |
45 |
46 | # 主函数
47 | if __name__ == "__main__":
48 | # 基于unicode模式生成10个汉字
49 | for _ in range(10):
50 | print(unicode_zh())
51 |
52 | print("------上面的汉字是不是很多不认识, 哈哈哈------\n\n")
53 |
54 | print("------下面的汉字是不是认识很多-------")
55 |
56 | # 基于gb2312模式生成10个汉字
57 | for _ in range(10):
58 | print(gbk2312_zh())
59 |
--------------------------------------------------------------------------------
/selenium_python/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/selenium_python/.DS_Store
--------------------------------------------------------------------------------
/selenium_python/1/下载地址.md:
--------------------------------------------------------------------------------
1 | # python 3.6.7版本下载地址:
2 |
3 | https://www.python.org/downloads/release/python-367/
4 |
5 | # selenium安装命令
6 |
7 | pip install selenium -U
8 |
9 | # PyCharm社区版下载:
10 |
11 | https://www.jetbrains.com/pycharm/download/
12 |
13 | # 驱动下载
14 |
15 | 国内地址:http://npm.taobao.org/
16 |
17 | 官方地址: https://www.seleniumhq.org/download/
18 |
19 | # selenium server下载
20 |
21 | 国内下载地址:https://npm.taobao.org/mirrors/selenium
22 |
--------------------------------------------------------------------------------
/selenium_python/2/1.1 Python3安装.md:
--------------------------------------------------------------------------------
1 | ## 下载链接
2 |
3 | https://www.python.org/downloads/release/python-367/
4 |
5 | ## 选择合适的系统版本下载
6 |
7 | 
8 |
9 | ## 配置命令可用
10 |
11 | 
--------------------------------------------------------------------------------
/selenium_python/2/2.1_base_sample.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from time import sleep
6 |
7 | from selenium import webdriver
8 | from selenium.webdriver.common.keys import Keys
9 |
10 |
11 | if __name__ == "__main__":
12 | driver = webdriver.Chrome()
13 |
14 | driver.get("http://www.python.org")
15 |
16 | assert "Python" in driver.title
17 |
18 | ele = driver.find_element_by_name("q")
19 |
20 | ele.clear()
21 |
22 | ele.send_keys("pycon")
23 |
24 | ele.send_keys(Keys.RETURN)
25 |
26 | assert "No results found." not in driver.page_source
27 |
28 | sleep(5)
29 |
30 | driver.close()
31 |
--------------------------------------------------------------------------------
/selenium_python/2/2.2_unit_sample.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 |
8 | from selenium import webdriver
9 | from selenium.webdriver.common.keys import Keys
10 |
11 |
12 | import unittest
13 |
14 |
15 | class PythonSearch(unittest.TestCase):
16 |
17 | def setUp(self):
18 | self.driver = webdriver.Chrome()
19 |
20 | def test_python_search(self):
21 | driver = self.driver
22 | driver.get("http://www.python.org")
23 |
24 | assert "Python" in driver.title
25 |
26 | ele = driver.find_element_by_name("q")
27 |
28 | ele.clear()
29 |
30 | ele.send_keys("pycon")
31 |
32 | ele.send_keys(Keys.RETURN)
33 |
34 | assert "No results found." not in driver.page_source
35 |
36 | def tearDown(self):
37 |
38 | sleep(5)
39 |
40 | self.driver.close()
41 |
42 |
43 | if __name__ == "__main__":
44 |
45 | unittest.main()
46 |
--------------------------------------------------------------------------------
/selenium_python/2/2.3_remote_sample.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 |
8 | from selenium import webdriver
9 | from selenium.webdriver.common.keys import Keys
10 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
11 |
12 | import unittest
13 |
14 |
15 | class PythonSearch(unittest.TestCase):
16 |
17 | def setUp(self):
18 | self.driver = webdriver.Remote(
19 | command_executor="http://127.0.0.1:4444/wd/hub",
20 | desired_capabilities=DesiredCapabilities.CHROME
21 | )
22 |
23 | def test_python_search(self):
24 | driver = self.driver
25 | driver.get("http://www.python.org")
26 |
27 | assert "Python" in driver.title
28 |
29 | ele = driver.find_element_by_name("q")
30 |
31 | ele.clear()
32 |
33 | ele.send_keys("pycon")
34 |
35 | ele.send_keys(Keys.RETURN)
36 |
37 | assert "No results found." not in driver.page_source
38 |
39 | def tearDown(self):
40 |
41 | sleep(5)
42 |
43 | self.driver.close()
44 |
45 |
46 | if __name__ == "__main__":
47 |
48 | unittest.main()
49 |
--------------------------------------------------------------------------------
/selenium_python/3/3.10_find_ele_by_css.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确css
17 | ele = driver.find_element_by_css_selector("#fieldset >input[@id='id-search-field']")
18 | print(ele)
19 |
20 | # 给错误css,看下定位到的结果是什么
21 | ele = driver.find_element_by_css_selector("search-field_error")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/3/3.11_find_child_ele.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | ele = driver.find_element_by_tag_name("fieldset").find_element_by_name("q")
17 | print(ele)
18 |
19 | driver.quit()
20 |
--------------------------------------------------------------------------------
/selenium_python/3/3.12_find_multiple_elements.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过xpath定位多个元素
17 | eles = driver.find_elements_by_xpath("//a")
18 | print(eles)
19 |
20 | # 通过tag name定位多个元素
21 | eles = driver.find_element_by_tag_name("li")
22 | print(eles)
23 |
24 | # 其他方法
25 | # driver.find_elements_by_id()
26 | # driver.find_elements_by_name()
27 | # driver.find_elements_by_class_name()
28 | # driver.find_elements_by_link_text()
29 | # driver.find_elements_by_partial_link_text()
30 | # driver.find_elements_by_css_selector()
31 |
32 | # 另外一种姿势
33 | # by 指定定位方式, value指定目标元素的定位参数
34 | # find_elements(by="id", value="id")
35 |
36 | driver.quit()
37 |
--------------------------------------------------------------------------------
/selenium_python/3/3.2_start_browser.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 |
9 |
10 | if __name__ == "__main__":
11 | # firefox
12 | driver = webdriver.Firefox()
13 | driver.get("http://www.python.org")
14 | sleep(1)
15 | driver.quit()
16 |
17 | # ie
18 | driver = webdriver.Ie()
19 | driver.get("http://www.python.org")
20 | sleep(1)
21 | driver.quit()
22 |
23 | # edge
24 | driver = webdriver.Edge()
25 | driver.get("http://www.python.org")
26 | sleep(1)
27 | driver.quit()
28 |
29 | # chrome
30 | driver = webdriver.Chrome()
31 | driver.get("http://www.python.org")
32 | sleep(1)
33 | driver.quit()
34 |
35 | # opera
36 | driver = webdriver.Opera()
37 | driver.get("http://www.python.org")
38 | sleep(1)
39 | driver.quit()
40 |
41 | # phantomjs
42 | driver = webdriver.PhantomJS()
43 | driver.get("http://www.python.org")
44 | sleep(1)
45 | driver.quit()
46 |
47 | # 其他
48 |
--------------------------------------------------------------------------------
/selenium_python/3/3.3_find_ele_by_id.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确id定位到元素
17 | ele = driver.find_element_by_id("id-search-field")
18 | print(ele)
19 |
20 | # 给错误id,看下定位到的结果是什么
21 | ele = driver.find_element_by_id("id-search-field_error")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/3/3.4_find_ele_by_name.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确name定位到元素
17 | ele = driver.find_element_by_name("q")
18 | print(ele)
19 |
20 | # 给错误name,看下定位到的结果是什么
21 | ele = driver.find_element_by_name("q_error")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/3/3.5_find_ele_by_link_text.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确链接文本
17 | ele = driver.find_element_by_link_text("Documentation")
18 | print(ele)
19 |
20 | # 给错误链接文本,看下定位到的结果是什么
21 | ele = driver.find_element_by_name("Documentation_error")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/3/3.6_find_ele_by_partial_link_text.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确链接文本
17 | ele = driver.find_element_by_partial_link_text("Document")
18 | print(ele)
19 |
20 | # 给错误链接文本,看下定位到的结果是什么
21 | ele = driver.find_element_by_partial_link_text("Document_error")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/3/3.7_find_ele_by_xpath.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确xpath
17 | ele = driver.find_element_by_xpath("//input[@id='id-search-field']")
18 | print(ele)
19 |
20 | # 给错误xpath,看下定位到的结果是什么
21 | ele = driver.find_element_by_xpath("//input[@id='id-search-field-error']")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/3/3.8_find_ele_by_tag_name.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确tag name
17 | ele = driver.find_element_by_tag_name("body")
18 | print(ele)
19 |
20 | # 给错误tag name,看下定位到的结果是什么
21 | ele = driver.find_element_by_tag_name("body_error")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/3/3.9_find_ele_by_class_name.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 |
11 | driver = webdriver.Chrome()
12 | driver.implicitly_wait(3)
13 |
14 | driver.get("http://www.python.org")
15 |
16 | # 通过正确class name
17 | ele = driver.find_element_by_class_name("search-field")
18 | print(ele)
19 |
20 | # 给错误class name,看下定位到的结果是什么
21 | ele = driver.find_element_by_class_name("search-field_error")
22 | print(ele)
23 |
24 | driver.quit()
25 |
--------------------------------------------------------------------------------
/selenium_python/4/4.1.1_input_text.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver.common.keys import Keys
9 |
10 |
11 | if __name__ == "__main__":
12 |
13 | driver = webdriver.Chrome()
14 | driver.get("http://www.python.org")
15 |
16 | # 查找输入框
17 | ele = driver.find_element_by_name("q")
18 | print(ele)
19 |
20 | # 输入str()
21 | ele.send_keys("str()")
22 | sleep(1)
23 |
24 | # 查找GO按钮
25 | btn = driver.find_element_by_id("submit")
26 | print(btn)
27 |
28 | # 输入回车
29 | btn.send_keys(Keys.RETURN)
30 | sleep(2)
31 |
32 | # 清空输入框,换个搜索词
33 | ele = driver.find_element_by_id("id-search-field")
34 | ele.clear()
35 | ele.send_keys("list")
36 |
37 | # 输入回车
38 | btn = driver.find_element_by_id("submit")
39 | btn.send_keys(Keys.RETURN)
40 | sleep(2)
41 |
42 | driver.quit()
43 |
--------------------------------------------------------------------------------
/selenium_python/4/4.1.2_input_text.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver.common.keys import Keys
9 | from selenium.webdriver import ActionChains
10 |
11 |
12 | if __name__ == "__main__":
13 |
14 | driver = webdriver.Chrome()
15 | action_chains = ActionChains(driver)
16 | driver.get("http://www.python.org")
17 |
18 | # 查找输入框
19 | ele = driver.find_element_by_name("q")
20 | action_chains.send_keys_to_element(ele, "list")
21 |
22 | # 查找GO按钮
23 | btn = driver.find_element_by_id("submit")
24 | action_chains.send_keys_to_element(btn, Keys.RETURN)
25 | action_chains.pause(2)
26 |
27 | # 执行动作链
28 | action_chains.perform()
29 |
30 | # 清空动作链
31 | action_chains.reset_actions()
32 |
33 | # 换个搜索词
34 | ele = driver.find_element_by_id("id-search-field")
35 | ele.clear()
36 | action_chains.send_keys_to_element(ele, "tuple")
37 |
38 | # 输入回车
39 | btn = driver.find_element_by_id("submit")
40 | action_chains.send_keys_to_element(btn, Keys.RETURN)
41 | action_chains.pause(2)
42 |
43 | # 执行动作链
44 | action_chains.perform()
45 |
46 | driver.quit()
47 |
--------------------------------------------------------------------------------
/selenium_python/4/4.2.1_mouse_click.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver import ActionChains
8 |
9 |
10 | if __name__ == "__main__":
11 | driver = webdriver.Chrome()
12 | action_chains = ActionChains(driver)
13 | driver.get("http://www.python.org")
14 |
15 | # 获取Docs链接元素,并加入动作链
16 | Docs = driver.find_element_by_link_text("Docs")
17 | action_chains.click(Docs)
18 | action_chains.pause(2)
19 |
20 | # 执行动作链
21 | action_chains.perform()
22 |
23 | driver.quit()
24 |
--------------------------------------------------------------------------------
/selenium_python/4/4.2.2_mouse_doubleclick.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver import ActionChains
8 |
9 |
10 | if __name__ == "__main__":
11 | driver = webdriver.Chrome()
12 | action_chains = ActionChains(driver)
13 | driver.get("http://www.python.org")
14 |
15 | # 获取About链接元素,并加入动作链
16 | About = driver.find_element_by_link_text("About")
17 | action_chains.context_click(About)
18 | action_chains.pause(2)
19 |
20 | # 执行动作链
21 | action_chains.perform()
22 |
23 | driver.quit()
24 |
--------------------------------------------------------------------------------
/selenium_python/4/4.2.3_mouse_rightclick.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver import ActionChains
8 |
9 |
10 | if __name__ == "__main__":
11 | driver = webdriver.Chrome()
12 | action_chains = ActionChains(driver)
13 | driver.get("http://www.python.org")
14 |
15 | # 获取About链接元素,并加入动作链
16 | About = driver.find_element_by_link_text("About")
17 | action_chains.double_click(About)
18 | action_chains.pause(2)
19 |
20 | # 执行动作链
21 | action_chains.perform()
22 |
23 | driver.quit()
24 |
--------------------------------------------------------------------------------
/selenium_python/4/4.2.4_mouse_move.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver import ActionChains
8 |
9 |
10 | if __name__ == "__main__":
11 | driver = webdriver.Chrome()
12 | action_chains = ActionChains(driver)
13 | driver.get("http://www.python.org")
14 |
15 | # 获取About链接元素,并加入动作链
16 | About = driver.find_element_by_link_text("About")
17 | action_chains.move_to_element(About)
18 | action_chains.pause(2)
19 |
20 | # 执行动作链
21 | action_chains.perform()
22 |
23 | driver.quit()
24 |
--------------------------------------------------------------------------------
/selenium_python/4/4.2.5_mouse_hold_on.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver import ActionChains
8 |
9 |
10 | if __name__ == "__main__":
11 | driver = webdriver.Chrome()
12 | action_chains = ActionChains(driver)
13 | driver.get("http://www.python.org")
14 |
15 | # 获取About链接元素,并加入动作链
16 | About = driver.find_element_by_link_text("About")
17 | action_chains.click_and_hold(About)
18 | action_chains.pause(2)
19 | # 使用下列的动作可以释放按下的鼠标
20 | # action_chains.release()
21 |
22 | # 执行动作链
23 | action_chains.perform()
24 |
25 | driver.quit()
26 |
--------------------------------------------------------------------------------
/selenium_python/4/4.2.6_mouse_drag_and_drop.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver import ActionChains
8 |
9 |
10 | if __name__ == "__main__":
11 | driver = webdriver.Chrome()
12 | action_chains = ActionChains(driver)
13 | driver.get("http://www.python.org")
14 |
15 | # 获取About链接元素,并加入动作链
16 | About = driver.find_element_by_link_text("About")
17 |
18 | Events = driver.find_element_by_link_text("Events")
19 | action_chains.drag_and_drop(About, Events)
20 | action_chains.pause(2)
21 |
22 | # 执行动作链
23 | action_chains.perform()
24 |
25 | driver.quit()
26 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.1_alert_win.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 |
10 |
11 | if __name__ == "__main__":
12 |
13 | driver = webdriver.Chrome()
14 | action_chains = ActionChains(driver)
15 |
16 | # 注意这里./demo.html一定要改为你实际的demo.html位置
17 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
18 |
19 | # 单击alert按钮,弹出alert窗口
20 | alert_btn = driver.find_element_by_id("alert_id")
21 | action_chains.click(alert_btn).perform()
22 |
23 | # 捕获alert窗口
24 | alert_win = driver.switch_to.alert
25 |
26 | # 打印下alert窗口文本
27 | print("alert text is [%s] " % alert_win.text)
28 |
29 | sleep(2)
30 |
31 | # 按下alert窗口的确定按钮,关闭alertc窗口
32 | alert_win.accept()
33 |
34 | sleep(2)
35 |
36 | driver.quit()
37 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.2_confirm_win.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 |
10 |
11 | # 按下确定按钮关闭弹窗
12 | def click_accept(driver, action_chains):
13 | # 注意这里./demo.html一定要改为你实际的demo.html位置
14 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
15 |
16 | # 单击confirm按钮,弹出confirm窗口
17 | confirm_btn = driver.find_element_by_id("confirm_id")
18 | action_chains.click(confirm_btn).perform()
19 |
20 | # 捕获confirm窗口
21 | confirm_win = driver.switch_to.alert
22 |
23 | # 打印下confirm窗口文本
24 | print("confirm text is [%s] " % confirm_win.text)
25 |
26 | sleep(1)
27 |
28 | # 按下confirm窗口的确定按钮,关闭confirm窗口
29 | confirm_win.accept()
30 |
31 |
32 | # 按下取消按钮关闭弹窗
33 | def click_cancel(driver, action_chains):
34 | # 注意这里./demo.html一定要改为你实际的demo.html位置
35 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
36 |
37 | # 单击confirm按钮,弹出confirm窗口
38 | confirm_btn = driver.find_element_by_id("confirm_id")
39 |
40 | # 重置action_chains
41 | action_chains.reset_actions()
42 | action_chains.click(confirm_btn).perform()
43 |
44 | # 捕获confirm窗口
45 | confirm_win = driver.switch_to.alert
46 |
47 | # 打印下confirm窗口文本
48 | print("confirm text is [%s] " % confirm_win.text)
49 |
50 | sleep(1)
51 |
52 | # 按下confirm窗口的取消按钮,关闭confirmc窗口
53 | confirm_win.dismiss()
54 |
55 | sleep(2)
56 |
57 |
58 | if __name__ == "__main__":
59 |
60 | driver = webdriver.Chrome()
61 | action_chains = ActionChains(driver)
62 |
63 | click_accept(driver, action_chains)
64 |
65 | sleep(2)
66 |
67 | click_cancel(driver, action_chains)
68 |
69 | driver.quit()
70 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.3_prompt_win.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 |
10 |
11 | # 按下确定按钮关闭弹窗
12 | def click_accept(driver, action_chains):
13 | # 注意这里./demo.html一定要改为你实际的demo.html位置
14 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
15 |
16 | # 单击prompt按钮,弹出prompt窗口
17 | prompt_btn = driver.find_element_by_id("prompt_id")
18 | action_chains.click(prompt_btn).perform()
19 |
20 | # 捕获prompt窗口
21 | prompt_win = driver.switch_to.alert
22 |
23 | # 打印下prompt窗口文本
24 | print("prompt text is [%s] " % prompt_win.text)
25 |
26 | sleep(1)
27 |
28 | # 按下prompt窗口的确定按钮,关闭prompt窗口
29 | prompt_win.accept()
30 |
31 |
32 | # 按下取消按钮关闭弹窗
33 | def click_cancel(driver, action_chains):
34 | # 注意这里./demo.html一定要改为你实际的demo.html位置
35 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
36 |
37 | # 单击prompt按钮,弹出prompt窗口
38 | prompt_btn = driver.find_element_by_id("prompt_id")
39 |
40 | # 重置action_chains
41 | action_chains.reset_actions()
42 | action_chains.click(prompt_btn).perform()
43 |
44 | # 捕获prompt窗口
45 | prompt_win = driver.switch_to.alert
46 |
47 | # 打印下prompt窗口文本
48 | print("prompt text is [%s] " % prompt_win.text)
49 |
50 | sleep(1)
51 |
52 | # 按下prompt窗口的取消按钮,关闭promptc窗口
53 | prompt_win.dismiss()
54 |
55 | sleep(2)
56 |
57 |
58 | # 给prompt窗体输入自定义文本
59 | def send_keys(driver, action_chains, text):
60 | # 注意这里./demo.html一定要改为你实际的demo.html位置
61 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
62 |
63 | # 单击prompt按钮,弹出prompt窗口
64 | prompt_btn = driver.find_element_by_id("prompt_id")
65 |
66 | # 重置action_chains
67 | action_chains.reset_actions()
68 | action_chains.click(prompt_btn).perform()
69 |
70 | # 捕获prompt窗口
71 | prompt_win = driver.switch_to.alert
72 |
73 | # 打印下prompt窗口文本
74 | print("prompt text is [%s] " % prompt_win.text)
75 | prompt_win.send_keys(text)
76 |
77 | sleep(1)
78 |
79 | # 按下prompt窗口的取消按钮,关闭promptc窗口
80 | prompt_win.accept()
81 |
82 | sleep(2)
83 |
84 |
85 | if __name__ == "__main__":
86 |
87 | driver = webdriver.Chrome()
88 | action_chains = ActionChains(driver)
89 |
90 | # 点击确定关闭
91 | click_accept(driver, action_chains)
92 | sleep(2)
93 |
94 | # 点击取消关闭
95 | click_cancel(driver, action_chains)
96 | sleep(2)
97 |
98 | # 输入文本
99 | send_keys(driver, action_chains, "我的公众号ID是: DeepTest")
100 | sleep(2)
101 |
102 | driver.quit()
103 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.4_select.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 | from selenium.webdriver.support.select import Select
10 |
11 |
12 | if __name__ == "__main__":
13 |
14 | driver = webdriver.Chrome()
15 | action_chains = ActionChains(driver)
16 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
17 |
18 | ele = driver.find_element_by_id("select_id")
19 |
20 | # 通过索引选中第一个
21 | Select(ele).select_by_index(0)
22 | sleep(2)
23 |
24 | # 通过value选中第2个
25 | Select(ele).select_by_value("value_2")
26 | sleep(2)
27 |
28 | # 通过文本选中第3个
29 | Select(ele).select_by_visible_text("测试数据3")
30 | sleep(2)
31 |
32 | driver.quit()
33 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.5_multi_select.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 | from selenium.webdriver.support.select import Select
10 |
11 |
12 | # 演示基本功能, 然后取消选中
13 | def select_basic(ele):
14 | # 通过索引选中第一个
15 | Select(ele).select_by_index(0)
16 | sleep(1)
17 |
18 | # 通过value选中第2个
19 | Select(ele).select_by_value("value_2")
20 | sleep(1)
21 |
22 | # 通过文本选中第3个
23 | Select(ele).select_by_visible_text("测试数据3")
24 | sleep(1)
25 |
26 | # 取消已选中的项
27 | Select(ele).deselect_all()
28 | sleep(1)
29 |
30 |
31 | # 通过文本选中所有项, 然后取消选中
32 | def select_all_by_text(ele):
33 | # 获取所有选项, 下面两种方式均可实现
34 | options = Select(ele).options
35 | # options = Select(ele).all_selected_options
36 |
37 | # 通过文本选中所有项
38 | for o in options:
39 | Select(ele).select_by_visible_text(o.text)
40 | sleep(0.5)
41 |
42 | # 取消已选中的项
43 | Select(ele).deselect_all()
44 | sleep(1)
45 |
46 |
47 | # 通过索引选中所有项, 然后取消选中
48 | def select_all_by_index(ele):
49 | # 获取所有选项, 下面两种方式均可实现
50 | options = Select(ele).options
51 | for i in range(0, len(options)):
52 | Select(ele).select_by_index(i)
53 | sleep(0.5)
54 | # 取消已选中的项
55 | Select(ele).deselect_all()
56 | sleep(1)
57 |
58 |
59 | # 通过value选中所有项, 然后取消选中
60 | def select_all_by_value(ele):
61 | # 获取所有选项, 下面两种方式均可实现
62 | options = Select(ele).options
63 | # options = Select(ele).all_selected_options
64 |
65 | # 通过文本选中所有项
66 | for o in options:
67 | Select(ele).select_by_value(o.get_attribute("value"))
68 | sleep(0.5)
69 |
70 | # 取消已选中的项
71 | Select(ele).deselect_all()
72 | sleep(1)
73 |
74 |
75 | if __name__ == "__main__":
76 |
77 | driver = webdriver.Chrome()
78 | action_chains = ActionChains(driver)
79 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
80 |
81 | ele = driver.find_element_by_id("multi_select_id")
82 |
83 | select_basic(ele)
84 |
85 | select_all_by_text(ele)
86 |
87 | select_all_by_index(ele)
88 |
89 | select_all_by_value(ele)
90 |
91 | sleep(3)
92 |
93 | driver.quit()
94 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.6_switch_windows.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 |
10 |
11 | def switch_to_win_1(driver):
12 | # 遍历所有windows handles,查找目标, 方式一
13 | handles = driver.window_handles
14 | index = 0
15 | for index in range(0, len(handles)):
16 | driver.switch_to.window(handles[index])
17 | if "百度一下,你就知道" in driver.title:
18 | break
19 |
20 | print(driver.title)
21 |
22 |
23 | def switch_to_win_2(driver):
24 | handles = driver.window_handles
25 | for handle in handles:
26 | driver.switch(handle)
27 | if "百度一下,你就知道" in driver.title:
28 | break
29 |
30 | print(driver.title)
31 |
32 |
33 | if __name__ == "__main__":
34 | driver = webdriver.Chrome()
35 | driver.implicitly_wait(5)
36 | action_chains = ActionChains(driver)
37 |
38 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
39 |
40 | # 打开b百度
41 | ele = driver.find_element_by_link_text("打开百度")
42 | action_chains.click(ele)
43 |
44 | action_chains.perform()
45 |
46 | # 获取当前window handle
47 | cur_handle = driver.current_window_handle
48 |
49 | # 方式一
50 | switch_to_win_1(driver)
51 |
52 | sleep(3)
53 |
54 | # 方式二
55 | switch_to_win_2(driver)
56 |
57 | sleep(3)
58 |
59 | driver.quit()
60 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.7_switch_frame.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 |
10 |
11 | # 切换至默认的frame上下文环境
12 | def switch_default_frame(driver):
13 | driver.switch_to.default_content()
14 |
15 | # 定位下alert_id按钮
16 | ele = driver.find_element_by_id("alert_id")
17 | print(ele)
18 |
19 |
20 | # 获取父frame
21 | def switch_parent_frame(driver):
22 | driver.switch_to.parent_frame()
23 | # 定位下alert_id按钮
24 | ele = driver.find_element_by_id("alert_id")
25 | print(ele)
26 |
27 |
28 | # 切换至指定的frame
29 | def switch_frame(driver):
30 | # 通过name属性切换
31 | driver.switch_to.frame('baidu')
32 | # 通过索引切换
33 | # driver.switch_to.frame(1)
34 | # 通过定位的元素切换
35 | # driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
36 | # 定位下百度一下按钮
37 | ele = driver.find_element_by_id("su")
38 | print(ele)
39 |
40 |
41 | if __name__ == "__main__":
42 | driver = webdriver.Chrome()
43 | driver.implicitly_wait(5)
44 | action_chains = ActionChains(driver)
45 |
46 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
47 |
48 | # 1
49 | switch_frame(driver)
50 | switch_default_frame(driver)
51 |
52 | sleep(2)
53 |
54 | # 2
55 | switch_frame(driver)
56 | switch_parent_frame(driver)
57 |
58 | sleep(3)
59 |
60 | driver.quit()
61 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.8_control_browser.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 |
10 |
11 |
12 | if __name__ == "__main__":
13 | driver = webdriver.Chrome()
14 | driver.implicitly_wait(5)
15 | action_chains = ActionChains(driver)
16 |
17 | # 访问百度首页
18 | driver.get("http://www.baidu.com")
19 | sleep(1)
20 |
21 | # 点击下新闻链接
22 | ele = driver.find_element_by_link_text("新闻")
23 | action_chains.click(ele).perform()
24 | sleep(3)
25 |
26 | # 最小化浏览器窗口
27 | driver.minimize_window()
28 | sleep(1)
29 |
30 | # 最大化浏览器窗口
31 | driver.maximize_window()
32 | sleep(1)
33 |
34 | # 设置浏览器窗口大小为 800 x 600
35 | driver.set_window_size(800, 600)
36 | sleep(1)
37 |
38 | # back动作
39 | driver.back()
40 | sleep(1)
41 |
42 | # forward动作
43 | driver.forward()
44 | sleep(1)
45 |
46 | # refresh动作
47 | driver.refresh()
48 |
49 | sleep(3)
50 |
51 | driver.quit()
52 |
--------------------------------------------------------------------------------
/selenium_python/4/4.3.9_manage_cookies.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from time import sleep
7 | from selenium import webdriver
8 | from selenium.webdriver import ActionChains
9 |
10 |
11 | if __name__ == "__main__":
12 | driver = webdriver.Chrome()
13 | driver.implicitly_wait(5)
14 | action_chains = ActionChains(driver)
15 |
16 | driver.get("http://www.baidu.com")
17 | sleep(3)
18 |
19 | # 默认的cookies为空
20 | cookies = driver.get_cookies()
21 | print(cookies)
22 |
23 | # 新增一些cookies
24 | driver.add_cookie({'name': 'foo', 'value': 'bar', 'path': '/', 'secure': True})
25 |
26 | # 再次获取所有cookies
27 | cookies = driver.get_cookies()
28 | print(cookies)
29 |
30 | # 删除指定的cookie
31 | driver.delete_cookie("name")
32 | # 再次获取所有cookies
33 | cookies = driver.get_cookies()
34 | print(cookies)
35 |
36 | # 获取指定的cookie
37 | # 注意要根据实际返回的cookie的数据结构来决定用下面的方式还是用get_cookie方法
38 | cookie = driver.get_cookies()[0]["value"]
39 | print(cookie)
40 |
41 | # 清空cookies
42 | driver.delete_all_cookies()
43 | cookies = driver.get_cookies()
44 | print(cookies)
45 |
46 | driver.quit()
47 |
--------------------------------------------------------------------------------
/selenium_python/4/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 窗口试验专用
6 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
54 |
55 |
63 |
64 | 打开百度
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/selenium_python/4/demo.html.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/small99/DevAuto/9c269fedbcb9e5bff5143d4823963abab6a1d5a9/selenium_python/4/demo.html.zip
--------------------------------------------------------------------------------
/selenium_python/5/5.10_frame_to_be_available_and_switch_to_it.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import frame_to_be_available_and_switch_to_it
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问示例页面
25 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
26 |
27 | # 检查frame'是否可用,如果可用则切换至该frame
28 | ff = wait.until(frame_to_be_available_and_switch_to_it((By.ID, "baidu")))
29 |
30 | # 打印结果, 可用则返回True
31 | print(ff)
32 |
33 | driver.quit()
34 |
--------------------------------------------------------------------------------
/selenium_python/5/5.11_invisibility_of_element_located.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import visibility_of_element_located
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问示例页面
25 | driver.get("file:///Users/lyy/Documents/project/DevAuto/selenium_python/4/demo.html")
26 |
27 | # 检查一个存在并可见的input元素
28 | alert = wait.until(visibility_of_element_located((By.ID, "alert_id")))
29 |
30 | # 打印结果,
31 | print(alert)
32 |
33 | # 检查一个存在并不可见的input元素, 返回False或抛出异常
34 | v = wait.until(visibility_of_element_located((By.ID, "visibility_id")))
35 |
36 | # 打印结果
37 | print(v)
38 |
39 | driver.quit()
40 |
--------------------------------------------------------------------------------
/selenium_python/5/5.1_implicitly_wait.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 |
6 | from selenium import webdriver
7 |
8 |
9 | if __name__ == "__main__":
10 | # 创建webdriver对象
11 | driver = webdriver.chrome()
12 |
13 | # 设置隐式等待, 时间可以自定,一般建议设置30s以内
14 | # 即webdriver最长等待超过30s,则抛出超时异常
15 | driver.implicitly_wait(30)
16 |
17 | # 这里一般可以正常访问
18 | driver.get("http://www.python.org")
19 |
20 | # 这里你要是没vpn翻墙,30s后抛出超时异常
21 | driver.get("http://www.google.com")
22 |
23 | driver.quit()
24 |
--------------------------------------------------------------------------------
/selenium_python/5/5.2_title_is.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入title_is类
11 | from selenium.webdriver.support.expected_conditions import title_is
12 |
13 |
14 | if __name__ == "__main__":
15 | driver = webdriver.Chrome()
16 |
17 | # 构建WebDriverWait对象
18 | # 最长超时时间为10s
19 | wait = WebDriverWait(driver, 10)
20 |
21 | # 访问百度首页
22 | driver.get("http://www.baidu.com")
23 |
24 | # 百度首页的页面标题为:百度一下,你就知道
25 | # 不知道如何看一个页面的标题?那你该回去洗洗睡了
26 | # 使用title_is判断首页标准
27 | title = wait.until(title_is("百度一下,你就知道"))
28 |
29 | # 这里将打印出True,表示页面标题正确
30 | print(title)
31 |
32 | # 这里将等待10s,然后抛出timeout异常
33 | # 注意这里用的until_not与上面until的区别
34 | title = wait.until_not(title_is("百度一下,你就知道"))
35 | print(title)
36 |
37 | driver.quit()
38 |
--------------------------------------------------------------------------------
/selenium_python/5/5.3_title_contains.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入title_is类
11 | from selenium.webdriver.support.expected_conditions import title_contains
12 |
13 |
14 | if __name__ == "__main__":
15 | driver = webdriver.Chrome()
16 |
17 | # 构建WebDriverWait对象
18 | # 最长超时时间为10s
19 | wait = WebDriverWait(driver, 10)
20 |
21 | # 访问百度首页
22 | driver.get("http://www.baidu.com")
23 |
24 | # 百度首页的页面标题为:百度一下,你就知道
25 | # 不知道如何看一个页面的标题?那你该回去洗洗睡了
26 | title = wait.until(title_contains("百度一下"))
27 | # 这里将打印出True,表示页面标题正确
28 | print(title)
29 |
30 | title = wait.until(title_contains("你就知道"))
31 | # 这里将打印出True,表示页面标题正确
32 | print(title)
33 |
34 | # 这里将等待10s,然后抛出timeout异常
35 | # 注意这里用的until_not与上面until的区别
36 | title = wait.until_not(title_contains("百度一下,你就知道"))
37 | print(title)
38 |
39 | driver.quit()
40 |
--------------------------------------------------------------------------------
/selenium_python/5/5.4_presence_of_element_located.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import presence_of_element_located
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问百度首页
25 | driver.get("http://www.baidu.com")
26 |
27 | # 判断百度搜索框是否存在, 其id为kw
28 | kw = wait.until(presence_of_element_located((By.ID, "kw")))
29 | print(kw)
30 |
31 | # 用name属性来判断
32 | wd = wait.until(presence_of_element_located((By.NAME, "wd")))
33 | print(wd)
34 |
35 | # 看看判断隐藏的元素
36 | rn = wait.until(presence_of_element_located((By.NAME, "rn")))
37 | print(rn)
38 |
39 | # 用一个不存在的id值来判断,将抛出异常
40 | kw = wait.until(presence_of_element_located((By.ID, "kw11111")))
41 |
42 | driver.quit()
43 |
--------------------------------------------------------------------------------
/selenium_python/5/5.5_visibility_of_element_located.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import visibility_of_element_located
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问百度首页
25 | driver.get("http://www.baidu.com")
26 |
27 | # 判断百度搜索框是否存在, 其id为kw
28 | kw = wait.until(visibility_of_element_located((By.ID, "kw")))
29 | print(kw)
30 |
31 | # 用name属性来判断
32 | wd = wait.until(visibility_of_element_located((By.NAME, "wd")))
33 | print(wd)
34 |
35 | # 看看判断隐藏的元素, 隐藏元素不可见,抛出异常
36 | rn = wait.until(visibility_of_element_located((By.NAME, "rn")))
37 | print(rn)
38 |
39 | driver.quit()
40 |
--------------------------------------------------------------------------------
/selenium_python/5/5.6_visibility_of.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import presence_of_element_located,visibility_of
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问百度首页
25 | driver.get("http://www.baidu.com")
26 |
27 | # 判断百度搜索框是否存在, 其id为kw
28 | kw_input = wait.until(presence_of_element_located((By.ID, 'kw')))
29 | kw = visibility_of(kw_input)
30 |
31 | # 这里将打印搜索框的WebElement对象
32 | print(kw)
33 |
34 | # 用name属性来判断
35 | wd_input = wait.until(presence_of_element_located((By.NAME, 'wd')))
36 | wd = visibility_of(wd_input)
37 | # 这里将打印搜索框的WebElement对象
38 | print(wd)
39 |
40 | # 看看判断隐藏的元素, 隐藏元素
41 | rn_input = wait.until(presence_of_element_located((By.NAME, 'rn')))
42 | rn = visibility_of(wd_input)
43 | # 这里将打印搜索框的WebElement对象
44 | print(rn)
45 |
46 | # 如果目标元素不可见,且width、height属性为0则抛出异常,大家可以自己试试
47 |
48 | driver.quit()
49 |
--------------------------------------------------------------------------------
/selenium_python/5/5.7_presence_of_all_elements_located.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问百度首页
25 | driver.get("http://www.baidu.com")
26 |
27 | # 判断是否存在至少一个input元素
28 | # 返回已经找到的元素的列表集
29 | kw = wait.until(presence_of_all_elements_located((By.XPATH, "//input")))
30 | print("===" * 10)
31 | print(kw)
32 |
33 | # 找一个不存在的元素试试
34 | # 抛出异常
35 | rn = wait.until(presence_of_all_elements_located((By.XPATH, "//input[@id='123']")))
36 | print("---" * 10)
37 | print(rn)
38 |
39 | driver.quit()
40 |
--------------------------------------------------------------------------------
/selenium_python/5/5.8_text_to_be_present_in_element.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问百度首页
25 | driver.get("http://www.baidu.com")
26 |
27 | # 判断 新闻 文本是否在指定的链接元素中
28 | kw = wait.until(text_to_be_present_in_element((By.NAME, "tj_trnews"), "新闻"))
29 |
30 | # 打印出True
31 | print(kw)
32 |
33 | driver.quit()
34 |
--------------------------------------------------------------------------------
/selenium_python/5/5.9_text_to_be_present_in_element_value.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | __author__ = "苦叶子"
4 |
5 | from selenium import webdriver
6 |
7 | # 导入WebDriverWait类
8 | from selenium.webdriver.support.ui import WebDriverWait
9 |
10 | # 导入定位方式
11 | from selenium.webdriver.common.by import By
12 |
13 | # 导入
14 | from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element_value
15 |
16 |
17 | if __name__ == "__main__":
18 | driver = webdriver.Chrome()
19 |
20 | # 构建WebDriverWait对象
21 | # 最长超时时间为10s
22 | wait = WebDriverWait(driver, 10)
23 |
24 | # 访问百度首页
25 | driver.get("http://www.baidu.com")
26 |
27 | # 判断 百度一下 文本是否在指定的input元素的value属性中
28 | kw = wait.until(text_to_be_present_in_element_value((By.ID, "su"), "百度一下"))
29 |
30 | # 打印出True
31 | print(kw)
32 |
33 | driver.quit()
34 |
--------------------------------------------------------------------------------
/test_pipeline:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent any
3 | stages{
4 | stage('Hello Stage') {
5 | steps {
6 | echo "hello world"
7 | }
8 | }
9 | stage("Second Stage"){
10 | steps {
11 | echo "second stage"
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/unittest_demo/readme.md:
--------------------------------------------------------------------------------
1 | Python3 Unittest 示例代码
2 |
--------------------------------------------------------------------------------