Reputation: 15
I am trying to perform the payment by credit card using dummy data using Selenium. The problem I am having is that #document doesn't show when I run my selenium code when i do it manually it only shows after I refresh the page but when I try to do the same thing in selenium even though the page refreshes the #document
doesn't show.
Html when done by selenium :
<body class="script-body">
<div class="container"></div>
<script type="text/javascript"></script>
<iframe src="https://libs.hipay.com/hostedfields/index.html#type=card&element=controller&instanceId=200803&referrer=https://stage-secure-gateway.hipay-tpp.com" frameborder="0" allowtransparency="true" scrolling="no" width="0" height="0" name="hipay-controller-200803" title="hipay-controller-200803" id="hipay-controller-200803" data-hipay-id="hostedfield-iframe"></iframe>
</body>
When i do it manualy :
My code :
WebElement ClkPaiementByCard = driver.findElement(By.id("payed-cart"));
js.executeScript("arguments[0].click();", ClkPaiementByCard);
driver.findElement(By.className("script-body")).sendKeys(Keys.F5);
WebElement CardNumber = driver.findElement(By.xpath(
"//div[@id=\"root\"]/div/div/form/div/div/input[@name=\"cardnumber\"]"));
CardNumber.clear();
CardNumber.sendKeys("4111 1111 1111 1111");
WebElement ExpDate = driver.findElement(By.xpath(
"//div[@id=\"root\"]/div/div/input[@name=\"cc-exp\"]"));
ExpDate.clear();
ExpDate.sendKeys("05/24");
WebElement CVC = driver.findElement(By.xpath(
"//div[@id=\"root\"]/div/div/input[@name=\"cvc\"]"));
CVC.clear();
CVC.sendKeys("123");
WebElement SubmitPaiement = driver.findElement(By.id("submit-button"));
js.executeScript("arguments[0].click();", SubmitPaiement);
I tried to do the switchto().frame()
but it never works I tried to perform an action that refreshes the page but it doesn't work neither can someone explain to me what I am doing wrong.
Upvotes: 1
Views: 863
Reputation: 193138
The iframe
is clearly visible. You need to switch to the iframe first to access the elements as follows:
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[starts-with(@id, 'hipay-controller') and @data-hipay-id='hostedfield-iframe']")));
preferably using WebDriverWait as follows:
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@id, 'hipay-controller') and @data-hipay-id='hostedfield-iframe']")));
Upvotes: 1