好的,已经修改
好的,我弄一下
user 是实体类,是的,那个写错了,修改为 <mapper namespace="com.course.mapper.userMapper">
,这个改好后问题还存在
现在错误变为
"C:\Program Files\Java\jdk1.8.0_202\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:D:\Java_IDE\IntelliJ IDEA 2021.1.3\lib\idea_rt.jar=50458:D:\Java_IDE\IntelliJ IDEA 2021.1.3\bin" -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_202\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\rt.jar;D:\me\java_test_pro\SpringbootMybatis\target\classes;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.5.6\spring-boot-starter-web-2.5.6.jar;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot-starter\2.5.6\spring-boot-starter-2.5.6.jar;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot\2.5.6\spring-boot-2.5.6.jar;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.5.6\spring-boot-autoconfigure-2.5.6.jar;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.5.6\spring-boot-starter-logging-2.5.6.jar;C:\Users\DD\.m2\repository\ch\qos\logback\logback-classic\1.2.6\logback-classic-1.2.6.jar;C:\Users\DD\.m2\repository\ch\qos\logback\logback-core\1.2.6\logback-core-1.2.6.jar;C:\Users\DD\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.14.1\log4j-to-slf4j-2.14.1.jar;C:\Users\DD\.m2\repository\org\apache\logging\log4j\log4j-api\2.14.1\log4j-api-2.14.1.jar;C:\Users\DD\.m2\repository\org\slf4j\jul-to-slf4j\1.7.32\jul-to-slf4j-1.7.32.jar;C:\Users\DD\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\DD\.m2\repository\org\yaml\snakeyaml\1.28\snakeyaml-1.28.jar;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.5.6\spring-boot-starter-json-2.5.6.jar;C:\Users\DD\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.12.5\jackson-databind-2.12.5.jar;C:\Users\DD\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.12.5\jackson-annotations-2.12.5.jar;C:\Users\DD\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.12.5\jackson-core-2.12.5.jar;C:\Users\DD\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.12.5\jackson-datatype-jdk8-2.12.5.jar;C:\Users\DD\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.12.5\jackson-datatype-jsr310-2.12.5.jar;C:\Users\DD\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.12.5\jackson-module-parameter-names-2.12.5.jar;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.5.6\spring-boot-starter-tomcat-2.5.6.jar;C:\Users\DD\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.54\tomcat-embed-core-9.0.54.jar;C:\Users\DD\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.54\tomcat-embed-el-9.0.54.jar;C:\Users\DD\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.54\tomcat-embed-websocket-9.0.54.jar;C:\Users\DD\.m2\repository\org\springframework\spring-web\5.3.12\spring-web-5.3.12.jar;C:\Users\DD\.m2\repository\org\springframework\spring-webmvc\5.3.12\spring-webmvc-5.3.12.jar;C:\Users\DD\.m2\repository\org\springframework\spring-aop\5.3.12\spring-aop-5.3.12.jar;C:\Users\DD\.m2\repository\org\springframework\spring-context\5.3.12\spring-context-5.3.12.jar;C:\Users\DD\.m2\repository\org\springframework\spring-expression\5.3.12\spring-expression-5.3.12.jar;C:\Users\DD\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.1.3\mybatis-spring-boot-starter-2.1.3.jar;C:\Users\DD\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.1.3\mybatis-spring-boot-autoconfigure-2.1.3.jar;C:\Users\DD\.m2\repository\org\mybatis\mybatis\3.5.5\mybatis-3.5.5.jar;C:\Users\DD\.m2\repository\org\mybatis\mybatis-spring\2.0.5\mybatis-spring-2.0.5.jar;C:\Users\DD\.m2\repository\org\projectlombok\lombok\1.18.20\lombok-1.18.20.jar;C:\Users\DD\.m2\repository\org\springframework\spring-jdbc\5.3.4\spring-jdbc-5.3.4.jar;C:\Users\DD\.m2\repository\org\springframework\spring-beans\5.3.4\spring-beans-5.3.4.jar;C:\Users\DD\.m2\repository\org\springframework\spring-core\5.3.4\spring-core-5.3.4.jar;C:\Users\DD\.m2\repository\org\springframework\spring-jcl\5.3.4\spring-jcl-5.3.4.jar;C:\Users\DD\.m2\repository\org\springframework\spring-tx\5.3.4\spring-tx-5.3.4.jar;C:\Users\DD\.m2\repository\com\alibaba\fastjson\1.2.76\fastjson-1.2.76.jar;C:\Users\DD\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.3.0.RELEASE\spring-boot-starter-jdbc-2.3.0.RELEASE.jar;C:\Users\DD\.m2\repository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;C:\Users\DD\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\DD\.m2\repository\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar" com.course.Application
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.6)
2022-11-08 18:24:49.474 INFO 37164 --- [ main] com.course.Application : Starting Application using Java 1.8.0_202 on LAPTOP-52L2UDTT with PID 37164 (D:\me\java_test_pro\SpringbootMybatis\target\classes started by DD in D:\me\java_test_pro\SpringbootMybatis)
2022-11-08 18:24:49.476 INFO 37164 --- [ main] com.course.Application : No active profile set, falling back to default profiles: default
2022-11-08 18:24:50.259 INFO 37164 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8082 (http)
2022-11-08 18:24:50.273 INFO 37164 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-11-08 18:24:50.273 INFO 37164 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.54]
2022-11-08 18:24:50.343 INFO 37164 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-11-08 18:24:50.344 INFO 37164 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 834 ms
2022-11-08 18:24:50.648 WARN 37164 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]: Factory method 'requestMappingHandlerMapping' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.core.log.LogDelegateFactory.getHiddenLog(Ljava/lang/String;)Lorg/apache/commons/logging/Log;
2022-11-08 18:24:50.648 WARN 37164 --- [ main] .s.c.a.CommonAnnotationBeanPostProcessor : Destroy method on bean with name 'application' threw an exception: java.lang.NullPointerException
2022-11-08 18:24:50.650 INFO 37164 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-11-08 18:24:50.659 INFO 37164 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-11-08 18:24:50.669 ERROR 37164 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.web.servlet.handler.AbstractHandlerMapping.<init>(AbstractHandlerMapping.java:83)
The following method did not exist:
org.springframework.core.log.LogDelegateFactory.getHiddenLog(Ljava/lang/String;)Lorg/apache/commons/logging/Log;
The method's class, org.springframework.core.log.LogDelegateFactory, is available from the following locations:
jar:file:/C:/Users/DD/.m2/repository/org/springframework/spring-core/5.3.4/spring-core-5.3.4.jar!/org/springframework/core/log/LogDelegateFactory.class
The class hierarchy was loaded from the following locations:
org.springframework.core.log.LogDelegateFactory: file:/C:/Users/DD/.m2/repository/org/springframework/spring-core/5.3.4/spring-core-5.3.4.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.core.log.LogDelegateFactory
Process finished with exit code 1
谢谢,这个改好了,问题还是存在
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.15</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
这是我的依赖项,还专门处理过版本
添加完后
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
还是报上面那个错误
汗 ,这个项目难以定位元素,图方便,使用了浏览器的获取 xpath,控件的 xpath 是正确的,我修改一下,加上显式等待试试
import time
import os
from selenium import webdriver
from common.basic import Base
from common.read_image import ocr
from selenium.webdriver.common.by import By
from config.conf import img_address
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://wlsq.daishan.gov.cn/ddWeb/user/login")
time.sleep(10)
# 登录
driver.find_element(By.XPATH, '//span[@class = "ant-input-affix-wrapper ant-input-affix-wrapper-lg"]/input[@placeholder="请输入帐户名"]').send_keys("cxc")
driver.find_element(By.XPATH, '//span[@class = "ant-input-affix-wrapper ant-input-affix-wrapper-lg"]/input[@placeholder="请输入密码"]').send_keys("admin123456?")
img = Base(driver).screenshot(os.path.join(img_address, str(int(time.time())) + ".png"))
text = ocr(img)
driver.find_element(By.XPATH, '//span[@class = "ant-input-affix-wrapper ant-input-affix-wrapper-lg"]/input[@placeholder="请输入验证码"]').send_keys(text)
driver.find_element(By.XPATH, '//button[@class="login_btn"]').click()
time.sleep(20)
# 点击基础数据
driver.find_element(By.XPATH, "//html[@id='htmlRoot']//div[@id='app']/div[@class='home-large']/div[@class='home-large-content']//div[@class='slick-track']/div//div[@class='home-large-content-item']//span[.=' 基础数据库 ']").click()
time.sleep(5)
# 添加基础人口
driver.find_element(By.XPATH, "//div[@class='table-operator']/button[@class='ant-btn ant-btn-primary']").click()
time.sleep(5)
# 输入姓名
driver.find_element(By.XPATH, "//div[@class='ant-form-item-control']/span[@class='ant-form-item-children']/input[@id='name']").send_keys("小龙")
time.sleep(5)
# 出生日期
driver.find_element(By.XPATH, "//span[@class='ant-calendar-picker']/div/input[@placeholder='请选择出生日期']").click()
# 出生日期输入框
driver.find_element(By.XPATH, "//div[@class='ant-calendar-panel']/div[@class='ant-calendar-input-wrap']/div[@class='ant-calendar-date-input-wrap']/input[@placeholder='请选择出生日期']").send_keys("1858-02-02")
# 点击地址
time.sleep(5)
driver.find_element(By.XPATH, '//input[@id="building_address_info"]').click()
# 点击地址页面搜索框
driver.find_element(By.CSS_SELECTOR, 'input[placeholder="请输入地址"]').send_keys("舟山市岱山县外达昆西南约330米")
time.sleep(5)
# 地址库页面查询按钮
driver.find_element(By.XPATH, "//html[@id='htmlRoot']/body/div[5]/div/div[@role='dialog']/div[@role='document']//form[@class='ant-form ant-form-inline']/div[@class='ant-row']//span[@class='table-page-search-submitButtons']/button[1]").click()
# 地址库页面选中数据
driver.find_element(By.XPATH, '//table[@class="ant-table-fixed"]/tbody[@class="ant-table-tbody"]/tr[@class="ant-table-row ant-table-row-level-0"]/td[3]').click()
# 地址库页面点击确定
driver.find_element(By.XPATH, '//div[@class="ant-modal-footer"]/div/button[2]').click()
time.sleep(5)
# 选择户口类别
driver.find_element(By.XPATH, '//div[@class="ant-form-item-control"]/span/div[@id="household_registration_category"]/div[@role="combobox"]/div').click()
# 选择户籍人口
driver.find_element(By.XPATH, "//html[@id='htmlRoot']/body/div[5]/div/div[@role='dialog']/div[@role='document']//div[@class='ant-select-dropdown-content']/ul[@role='listbox']/li[1]/span[@title='户籍人口']").click()
# 选择性别
driver.find_element(By.XPATH, "//html[@id='htmlRoot']//div[@id='sex']//div[@class='ant-select-selection__placeholder']").click()
# 男
driver.find_element(By.XPATH, "//html[@id='htmlRoot']/body/div[3]/div/div[@role='dialog']/div[@role='document']//div[@class='ant-select-dropdown-content']/ul[@role='listbox']/li[2]/span[@title='男']").click()
# 联系方式
driver.find_element(By.XPATH, "//html[@id='htmlRoot']//input[@id='phone_number']").send_keys("15203141442")
# 证件号码
driver.find_element(By.XPATH, "//html[@id='htmlRoot']//input[@id='id_card']").send_keys("42010119720727663X")
# 入户状态
driver.find_element(By.XPATH, "//html[@id='htmlRoot']//div[@id='household_status']//div[@class='ant-select-selection__placeholder']").click()
# 点击一致
driver.find_element(By.XPATH, "//html[@id='htmlRoot']/body/div[3]/div/div[@role='dialog']/div[@role='document']/div[@class='ant-modal-content']/div[5]/div/div[@class='ant-select-dropdown ant-select-dropdown--single ant-select-dropdown-placement-bottomLeft']/div[@class='ant-select-dropdown-content']/ul[@role='listbox']/li[1]/span[@title='一致']").click()
# 点击确定
driver.find_element(By.XPATH, "//html[@id='htmlRoot']/body/div[3]/div/div[@role='dialog']/div[@role='document']//div[@class='ant-modal-footer']/button[1]")
time.sleep(10)
driver.close()
运行后
Traceback (most recent call last):
File "D:/dingdang_project/DDJX_ChangTu/libs/Q_test.py", line 69, in <module>
driver.find_element(By.XPATH, "//html[@id='htmlRoot']/body/div[5]/div/div[@role='dialog']/div[@role='document']//div[@class='ant-select-dropdown-content']/ul[@role='listbox']/li[1]/span[@title='户籍人口']").click()
File "D:\work software\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "D:\work software\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "D:\work software\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//html[@id='htmlRoot']/body/div[5]/div/div[@role='dialog']/div[@role='document']//div[@class='ant-select-dropdown-content']/ul[@role='listbox']/li[1]/span[@title='户籍人口']"}
(Session info: chrome=99.0.4844.51)
运行两次点击会报:AttributeError: 'NoneType' object has no attribute 'click'
现在主要用了这个 click 方法