|
@@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.time.Duration;
|
|
|
+import java.util.NoSuchElementException;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
@@ -102,6 +103,33 @@ public class SmsServiceImpl implements SmsApi {
|
|
|
// 等待页面加载完成
|
|
|
wait.until(ExpectedConditions.urlContains("middlePage"));
|
|
|
|
|
|
+ // 使用 CSS Selector 定位整个复选框 label
|
|
|
+ WebElement checkboxLabel = wait.until(ExpectedConditions.elementToBeClickable(
|
|
|
+ By.cssSelector("label.el-checkbox.login_agreement")
|
|
|
+ ));
|
|
|
+ // 滚动到元素(可选)
|
|
|
+ ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", checkboxLabel);
|
|
|
+ log.info("尝试点击复选框...");
|
|
|
+ // 使用JavaScript点击确保不被拦截
|
|
|
+ ((JavascriptExecutor) driver).executeScript("arguments[0].click();", checkboxLabel);
|
|
|
+ log.info("点击操作完成,开始验证状态...");
|
|
|
+
|
|
|
+ // 验证是否选中
|
|
|
+ WebElement hiddenInput = driver.findElement(By.cssSelector("label.login_agreement input.el-checkbox__original"));
|
|
|
+ log.info("找到元素hiddenInput:{} ", hiddenInput);
|
|
|
+ boolean isChecked = (Boolean) ((JavascriptExecutor) driver).executeScript("return arguments[0].checked;", hiddenInput);
|
|
|
+ log.info("复选框状态:{} ", isChecked); // 应为 true
|
|
|
+
|
|
|
+ try{
|
|
|
+ // 验证是否选中(可选)
|
|
|
+ WebElement checkboxInput2 = wait.until(ExpectedConditions.elementToBeClickable(
|
|
|
+ By.xpath("//span[contains(@class, 'el-checkbox__input is-checked')]")
|
|
|
+ ));
|
|
|
+ log.info("找到元素checkboxInput2: {}", checkboxInput2);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("元素未找到!");
|
|
|
+ }
|
|
|
+
|
|
|
// 手机号输入框定位
|
|
|
WebElement phoneInput = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@type='number' and @maxlength='11']")));
|
|
|
phoneInput.sendKeys(phoneNumber);
|
|
@@ -173,18 +201,17 @@ public class SmsServiceImpl implements SmsApi {
|
|
|
|
|
|
Thread.sleep(3000);
|
|
|
|
|
|
- // 点击协议复选框(使用优化方案)
|
|
|
- WebElement agreementLabel = new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@class,'login_agreementGroup')]//input[@type='checkbox']/ancestor::label[1]")));
|
|
|
-
|
|
|
- // 使用Actions确保点击成功
|
|
|
- new Actions(driver).scrollToElement(agreementLabel).moveToElement(agreementLabel).click().perform();
|
|
|
+// // 点击协议复选框(使用优化方案)
|
|
|
+// WebElement agreementLabel = new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@class,'login_agreementGroup')]//input[@type='checkbox']/ancestor::label[1]")));
|
|
|
+//
|
|
|
+// // 使用Actions确保点击成功
|
|
|
+// new Actions(driver).scrollToElement(agreementLabel).moveToElement(agreementLabel).click().perform();
|
|
|
|
|
|
|
|
|
// 定位并点击第二个登录按钮
|
|
|
By loginButtonSelector = By.xpath(
|
|
|
"//div[@id='login_mobile']/button[contains(@class, 'login_btn') " +
|
|
|
- "and not(contains(@style, 'display: none')) " +
|
|
|
- "and position()=2]"
|
|
|
+ "and not(contains(@style, 'display: none'))]"
|
|
|
);
|
|
|
|
|
|
WebElement loginButton = wait.until(d -> {
|
|
@@ -218,7 +245,7 @@ public class SmsServiceImpl implements SmsApi {
|
|
|
|
|
|
log.info("[校验验证码登录]登录成功,手机号:{},验证码:{}", phoneNumber, verificationCode);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[校验验证码登录]异常:{0}", e);
|
|
|
+ log.error("[校验验证码登录]异常:{}", e.getMessage());
|
|
|
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "触发校验验证码登录失败");
|
|
|
} finally {
|
|
|
WebDriverContextManagerUtil.destroySession(sId);
|