【发布时间】:2021-04-18 18:07:06
【问题描述】:
在this website 如何在 selenium 中为手机字段选择带有标志和拨号代码下拉列表的国际电话输入。硒代码没有选择
我写的代码。
<div class="control-group ">
<label class="control-label required" for="CellPhone">Cell Phone</label>
<div class="controls">
<input class="form-control phone-number" data-val="true" data-val-intltel="Invalid number" data-val-required="The Cell Phone field is required." id="CellPhone" name="CellPhone" type="text" value="" />
<span class="help-block">
<span class="field-validation-valid" data-valmsg-for="CellPhone" data-valmsg-replace="true"></span>
</span>
</div>
</div>
package testing123;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class dancekarwebsite1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Vpatiballa\\Desktop\\Lib\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://dancekar.com/parent-center/register");
driver.manage().window().maximize();
//*[@id="Email"]
//Actions actions = new Actions(driver);
// Scroll Down using Actions class
// actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,250)", "");
//driver.findElement(By.xpath("//div[@class='selected-flag']")).click();
Actions action = new Actions(driver);
WebElement optionsList = driver.findElement(By.xpath("//div[@class='selected-flag']"));
action.moveToElement(optionsList);
List<WebElement> options = driver.findElements(By.xpath("//div[@class='selected-flag']"));
for(WebElement option : options) {
if (option.getText().equals("United Kingdom +44")) {
option.click();
}
}
}
}
【问题讨论】:
-
您的问题解决了吗?