gpt4 book ai didi

javascript - Selenium Webdriver 自动完成文本框

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

我一直在尝试在网站中进行注册过程,我使用以下脚本,

    package agent;

import java.util.regex.Pattern;
import java.awt.List;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class TaxRegistration {
private static final TaxRegistration Driver = null;
private WebDriver driver;
WebDriverWait wait;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private By tagText = By.id("AddressDetails_City");


@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver","E:/Vignesh/Automation/New folder (2)/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
wait = new WebDriverWait(driver, 5);
baseUrl = "http://govreports.com.au/dev/taxagentt1.html";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void testBASFormWebdriver() throws Exception {
driver.get("http://govreports.com.au/dev/taxagentt1.html");
driver.findElement(By.id("BAS")).click();
Thread.sleep(1000);
driver.findElement(By.id("TFND")).click();
Thread.sleep(1000);
driver.findElement(By.id("PAYG")).click();
Thread.sleep(1000);
driver.findElement(By.id("TPAR")).click();
Thread.sleep(1000);
//((JavascriptExecutor)driver).executeScript("scroll(0,2000)");
Thread.sleep(1000);
driver.findElement(By.id("OUT")).click();
Thread.sleep(1000);
//((JavascriptExecutor)driver).executeScript("scroll(0,1000)");
Thread.sleep(1000);
driver.findElement(By.id("BUL")).click();
Thread.sleep(1000);
driver.findElement(By.id("NUL")).click();
Thread.sleep(1000);
driver.findElement(By.id("IUL")).click();
Thread.sleep(1000);
//((JavascriptExecutor)driver).executeScript("scroll(0,6000)");
Thread.sleep(1000);
driver.findElement(By.cssSelector("a.btn.btn-default > b")).click();
Thread.sleep(2000);
driver.findElement(By.id("AgentNo")).clear();
driver.findElement(By.id("AgentNo")).sendKeys("78301003");
driver.findElement(By.id("AgentName")).clear();
driver.findElement(By.id("AgentName")).sendKeys("Vignesh Check");
driver.findElement(By.id("SendQuote")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("(//input[@name='plancodeTPAR'])[2]")).click();
driver.findElement(By.xpath("(//input[@value='1'])[9]")).clear();
driver.findElement(By.xpath("(//input[@value='1'])[9]")).sendKeys("2");
driver.findElement(By.id("Proceed")).click();
Thread.sleep(5000);
driver.findElement(By.id("ABN")).click();
driver.findElement(By.id("ABN")).clear();
driver.findElement(By.id("ABN")).sendKeys("19087046080");
driver.findElement(By.id("BusinessName")).click();
Thread.sleep(2000);
driver.findElement(By.id("Username")).clear();
driver.findElement(By.id("Username")).sendKeys("vikireg02@govreports.com.au");
driver.findElement(By.id("Password")).clear();
driver.findElement(By.id("Password")).sendKeys("Viki2607");
driver.findElement(By.id("ConfirmPassword")).clear();
driver.findElement(By.id("ConfirmPassword")).sendKeys("Viki2607");
String capColorDropDown = "//span[@role='listbox']";
driver.findElement(By.xpath(capColorDropDown)).click();
String itemName = "Orange";
String listId = "color_listbox";
Thread.sleep(2000);
String xpathForItem = "//ul[@id='Salutation_listbox']/li[@class='k-item' and text()='Mr']";
driver.findElement(By.xpath(xpathForItem)).click();
driver.findElement(By.id("FirstName")).click();
driver.findElement(By.id("FirstName")).clear();
driver.findElement(By.id("FirstName")).sendKeys("Vignesh");
driver.findElement(By.id("LastName")).click();
driver.findElement(By.id("LastName")).clear();
driver.findElement(By.id("LastName")).sendKeys("Ks");
driver.findElement(By.id("TelephoneAreaCode")).click();
driver.findElement(By.id("TelephoneAreaCode")).clear();
driver.findElement(By.id("TelephoneAreaCode")).sendKeys("02");
driver.findElement(By.id("TelephoneNumber")).click();
driver.findElement(By.id("TelephoneNumber")).clear();
driver.findElement(By.id("TelephoneNumber")).sendKeys("2356895623");
driver.findElement(By.id("AddressDetails_Line1")).clear();
driver.findElement(By.id("AddressDetails_Line1")).sendKeys("Walker Street");

//我必须从下拉值(自动完成文本框)中选择城市,我已经使用了下面的行,但它对我不起作用

**`

driver.findElement(By.id("AddressDetails_City")).click();`
wait.until(ExpectedConditions.presenceOfElementLocated(tagText));
WebElement textBoxElement = driver.findElement(tagText);
textBoxElement.sendKeys("sydn");
selectOptionWithText("SYDNEY, NSW, Australia, 1001");
//selectOptionWithIndex(0);**
Thread.sleep(2000);
driver.findElement(By.linkText("Next")).click();
Thread.sleep(2000);
}


private void selectOptionWithIndex(int i) {
// TODO Auto-generated method stub

}

private void selectOptionWithText(String string) {
// TODO Auto-generated method stub

}

@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}

private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}

我无法在地址部分填写城市、州、邮政编码和国家/地区字段。我无法访问这些字段中的自动完成值。我在脚本中用 ** 符号突出显示了问题区域。

我认为该网站是可公开访问的。有人可以帮我解决吗?

最佳答案

您能否单独注释该网址,因为您在脚本中提到的网址说“由于不活动而注销”。

关于javascript - Selenium Webdriver 自动完成文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39610461/

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