当前位置:网站首页>Implementation of switching windows and capturing data in selenium mode
Implementation of switching windows and capturing data in selenium mode
2022-04-23 04:47:00 【Zijia 113】
selenium The method of switching windows under the is as follows
for handle in driver.window_handles:
driver.switch_to_window(handle)
Specific applications can be tested with the following examples ( The code is as follows ):
from selenium import webdriver
import time
import random
import csv
# 1. Bypass slider verification
inquire_company=input(' Please enter the name of the company to query :')
option=webdriver.ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')
driver=webdriver.Chrome(chrome_options=option)
# Open the url
url='https://www.qcc.com/'
driver.get(url=url)
driver.find_element_by_xpath('//*[@id="searchKey"]').send_keys(inquire_company)
# driver.find_element_by_xpath('/html/body/div/div[2]/section[1]/div/div/div/div[1]/div/div/span/button').click()
# Click to query
button=driver.find_element_by_xpath('/html/body/div/div[2]/section[1]/div/div/div/div[1]/div/div/span/button')
driver.execute_script("arguments[0].click();", button)
# driver.implicitly_wait(60)
# Click on the first search result
driver.find_element_by_xpath('/html/body/div/div[2]/div[2]/div[3]/div/div[2]/div/table/tr[1]/td[3]/div/div[1]/span[1]/a').click()
# driver.implicitly_wait(30)
# Point out a new window , Need to switch windows
for handle in driver.window_handles:
driver.switch_to_window(handle)
# text2=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[3]/td[2]/div/div/span[2]/span/a').size
with open(' Enterprise information .csv','w')as f:
headers1=[' Company name ',' outbound investment ']
control_company=driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div[1]/div[2]/div[2]/div[1]/div/div/span[1]/h1').text
headers2=[control_company,' Serial number ',' Name of invested enterprise ',' Legal representative ',' The registered capital ',' Date of establishment ',' state ',' Shareholding ratio ',' Subscribed capital contribution ']
f_csv=csv.writer(f)
f_csv.writerow(headers1)
f_csv.writerow(headers2)
try:
for i in range(2,100):
company_name=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[{}]/td[2]/div/div/span[2]/span/a'.format(i)).text
company_role=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[{}]/td[3]/div/div/span/span/a'.format(i)).text
company_money=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[{}]/td[4]/div/span'.format(i)).text
bulild_time=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[{}]/td[5]/div/span'.format(i)).text
company_state=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[{}]/td[6]/span/span'.format(i)).text
control_per=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[{}]/td[7]/div/span'.format(i)).text
out_money=driver.find_element_by_xpath('//*[@id="touzilist"]/div[2]/table/tr[{}]/td[8]/div/span'.format(i)).text
content=[' ',i-1,company_name,company_role,company_money,bulild_time,company_state,control_per,out_money]
f_csv.writerow(content)
print(' The first {} A controlling company is :'.format(i)+company_name)
except :
pass
driver.quit()
# print(text2)
An application implementation that can be tested directly , After configuring the environment, you can directly test , Please leave a message if you have any questions .
Encountered bug summary :
bug1:
selenium.common.exceptions.WebDriverException: Message: element click intercepted: Element … is not clickable at point (201, 298). Other element would receive the click:
terms of settlement :
Original code
driver.find_element_by_xpath(‘//[@id=“login-form”]/div[5]/button’).click
Change it to
button=driver.find_element_by_xpath('//[@id=“login-form”]/div[5]/button’)
driver.execute_script(“arguments[0].click();”, button)
版权声明
本文为[Zijia 113]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230442576639.html
边栏推荐
- leetcode001--返回和为target的数组元素的下标
- Open the past and let's start over.
- C# List字段排序含有数字和字符
- Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
- PHP 统计指定文件夹下文件的数量
- win10, mysql-8.0.26-winx64. Zip installation
- La caméra Unity tourne avec la souris
- Spark FAQ sorting - must see before interview
- List remove an element
- Innovation training (IX) integration
猜你喜欢

用LCR表完美测试无线充电系统中的线圈

Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000

Key points of AWS eks deployment and differences between console and eksctl creation

Recommended scheme of national manufactured electronic components for intelligent electronic scales

Flink's important basics

Excel protects worksheets and workbooks from damage
![[paper reading] [3D target detection] point transformer](/img/c5/b1fe5f206b5fe6e4dcd88dce11592d.png)
[paper reading] [3D target detection] point transformer

Innovation training (IV) preliminary preparation - server

QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效

Innovation training (IX) integration
随机推荐
JS generates a specified number of characters according to some words
Custom switch control
[timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
Arduino UNO r3+LCD1602+DHT11
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
IDE idea automatic compilation and configuration of on update action and on frame deactivation
C language: spoof games
io. Platform. packageRoot; // ignore: deprecated_ Member_ use
Innovation training (XI) airline ticket crawling company information
Innovation training (V) configuration information
Leetcode008 -- implement strstr() function
Migrate from MySQL database to AWS dynamodb
Wechat payment function
win10, mysql-8.0.26-winx64. Zip installation
Innovation training (VII) FBV view & CBV view
leetcode006--查找字符串数组中的最长公共前缀
Innovation training (XII) reptile
敏捷实践 | 提高小组可预测性的敏捷指标
Redis command Encyclopedia
Differences among electric drill, electric hammer and electric pick