gpt4 book ai didi

java - 如何在 firefox 中使用 webdriver 将 key 发送到电话字段?

转载 作者:行者123 更新时间:2023-11-28 21:04:48 25 4
gpt4 key购买 nike

   package erjan.testNG.personal_cabinet;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

public class Login_test {
WebDriver firefox ;
@Test
public void f() {
WebElement login_form

= firefox.findElement(By.id("login-form")) ;

WebElement phone_field = firefox.findElement(By.className("phone-username")) ;

WebElement password_field = firefox.findElement(By.xpath("//input[@type=\"text\"]"));

Assert.assertNotNull(login_form) ;
Assert.assertNotNull(phone_field) ;
Assert.assertNotNull(password_field);


phone_field.sendKeys("4457653245");

String x = phone_field.getText() ;
System.out.println("here we go!!!!!!!!! " + x) ;


}

@BeforeMethod
public void beforeMethod() {

firefox = new FirefoxDriver();
firefox.get("http://test.naimi.me/astana/login");

}

@AfterMethod
public void afterMethod() {
}

}

rrr

我看到 firefox 打开,但我没有看到我的号码被插入到电话字段中!或者它发生得很快?或者可能是因为它必须以某种方式标准化?

我是否应该以某种方式“减慢”输入以查看逐个输入的输入?我应该使用显式等待吗?

最佳答案

你说你没有看到它,但你得到了 x 中的值吗?与其拖慢代码速度,不如尝试在 IDE 中通过 Debug模式运行它,或者包含一些日志记录语句以帮助您查看代码在做什么。

要尝试的一件事是,如果字段中已有文本,请先清除该文本字段:

phone_field.clear();
phone_field.sendKeys("4457653245");

关于java - 如何在 firefox 中使用 webdriver 将 key 发送到电话字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28607249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com