I have the following JS HTML Element:
document.querySelector('[value="fixedsumcredit_kp"]')
<input id="-0198e3aa-d2b1-46ce-bdf0-192e60662cd3-fixedsumcredit_kp" type="radio" name="-0198e3aa-d2b1-46ce-bdf0-192e60662cd3" value="fixedsumcredit_kp" style="height: 100%; opacity: 0; position: absolute; width: 100%; top: 0px; left: 0px; z-index: 1; cursor: pointer; -webkit-tap-highlight-color: rgba(255, 255, 255, 0);">
I tried to click it via Selenium and jsExecutor as follows:
@FindBy(xpath = "//input[@value='fixedsumcredit_kp']")
public WebElement oneKlarna_ratenkauf_6;
jsExecutor.executeScript("arguments[0].click();", oneKlarna_ratenkauf_6);
and
WebElement oneKlarna = (WebElement) jsExecutor.executeScript("document.querySelector("value='fixedsumcredit_kp'")");
System.out.println("oneKlarna: " + oneKlarna);
jsExecutor.executeScript("arguments[0].click();", oneKlarna);
First script does not click and second script does not create the JS "WebElement oneKlarna"
The console click on the other hand works fine in chrome developer console:
document.querySelector('[value="fixedsumcredit_kp"]').click()
My question is: How to click the displayed "input" HTML element in Selenium correctly?
UPDATE:
I have the followin iframe
around the HTML Element:
<iframe id="klarna-klarna-main" name="klarna-klarna-main" title="Klarna" scrolling="no" frameborder="0" src="https://js.playground.klarna.com/eu/kp/v1.0.0-23083-g146e667ef2/main.html#data=%7B%22onShowExternalDocumentRegistered%22%3Afalse%2C%22fullscreenIframeID%22%3A%22klarna-klarna-fullscreen%22%2C%22popupWindowEnabled%22%3Afalse%2C%22nativeHookApiSupported%22%3Afalse%2C%22nativeHookApiFeatures%22%3A%5B%5D%2C%22paymentMethodCategory%22%3A%22klarna%22%2C%22purchaseCountry%22%3A%22DE%22%2C%22scheme%22%3Atrue%2C%22sessionType%22%3A%22payments%22%2C%22sessionID%22%3A%2270b4ebfe-6ae5-5596-8a24-8ddcd540e0d3%22%2C%22merchantName%22%3A%22Playground%20Demo%20Merchant%22%2C%22environment%22%3A%22playground%22%7D&" style="height: 701px; width: 100%; max-width: 600px; min-width: 280px; display: inline;"></iframe>
Is the behaviour known to you?
2
Answers
did the trick!
The element is a dynamic element so to click on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:
Using cssSelector:
Using xpath: