Selenium fails to locate the iframe by ID
and Name
.
This is for an automated checkout test on Shopify. The specific issue lies within the p
As per the images you have shared the is having dynamic attributes so to locate and switch to the desired
you have to:
You can use either of the following solutions:
cssSelector:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.card-fields-iframe[id^='card-fields-number-'][src*='shopifycs']")));
xpath:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@class='card-fields-iframe' and starts-with(@id,'card-fields-number-')][contains(@src, 'shopifycs')]")));
Here you can find a relevant discussion on Ways to deal with #document under iframe