this should be so simple but I'm obviously missing something:
<div>
<label>
Scenario
<select id="scenarios">
<option value="0">Default (Visa)</option>
<option value="1">Secondary (Amex)</option>
</select>
<button onclick="pickScenario()">Select</button>
</label>
<label style="padding-left: 2em;">
Custom Amount: $
<input type="text" id="custom_amount">
</label>
</div>
I keep getting NullPointerExceptions returned when trying to locate any of the three elements (scenarioDropdown, selectButton, customAmount) using the code below ... I've tried all three with id, xpath, and css but below I'm showing one way per element:
@FindBy(css = "#scenarios")
private WebElement scenariosDropdown;
@FindBy(xpath = "//button[contains(.,'Select')]")
private WebElement select;
@FindBy(how = How.ID, using = "custom_amount")
private WebElement customAmount;
private WebDriver driver;
public void selectScenario(String scenario) {
Select select = new Select(scenariosDropdown);
select.deselectAll();
select.selectByVisibleText(scenario);
}
void clickSelect() {
select.click();
}
public void enterCustomAmount(String amount) {
customAmount.clear();
customAmount.sendKeys(amount);
}
running a test that uses the method below ...
public void testWhileBroken() {
// select Scenario Two
cc.selectScenario("Secondary (Amex)");
// enter a Custom Amount
cc.enterCustomAmount("1.23");
// click Select
cc.clickSelect();
}
... returns:
Aug 16, 2017 9:07:16 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
java.lang.NullPointerException
at org.openqa.selenium.support.ui.Select.<init>(Select.java:44)
at apps.web.modules.staplespay.CreditCardsScreen.selectScenario(CreditCardsScreen.java:27)
What is the super obvious thing that I'm missing here?
Aucun commentaire:
Enregistrer un commentaire