I am trying to use Selenium in Python to retrieve a specific HTML element, more specifically its value.
`<input type="hidden" id="FunCaptcha-Token" name="fc-token" value="702178f80cd6ade39.2875608305|r=eu-west-1|meta=3|meta_width=558|meta_height=523|metabgclr=transparent|metaiconclr=%23555555|guitextcolor=%23000000|pk=2CB16598-CB82-4CF7-B332-5990DB66F3AB|at=40|ag=101|cdn_url=https%3A%2F%2Fclient-api.arkoselabs.com%2Fcdn%2Ffc|lurl=https%3A%2F%2Faudio-eu-west-1.arkoselabs.com|surl=https%3A%2F%2Fclient-api.arkoselabs.com|smurl=https%3A%2F%2Fclient-api.arkoselabs.com%2Fcdn%2Ffc%2Fassets%2Fstyle-manager">`
How can I retrieve it with Selenium?
I am using the following code:
token_element = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.NAME, "fc-token"))
)
logger.info(f"Token key{token_element}")
publickey = re.search(r'pk=([0-9A-Fa-f-]+)', token_element.get_attribute("value"))
logger.info(f"PUBLIC key{publickey}")
But it's never found. I added a print statement to check the DOM:
print(f"DOM\n {self.driver.page_source}")
But the element is missing.
Can someone help me resolve this problem?
Thanks in advance.
Use the below code to fetch value:
driver.switch_to.default_content()
arkose_iframe = driver.find_element(
By.XPATH,
"//iframe[@id='arkose_iframe']"
)
driver.switch_to.frame(arkose_iframe)
verification_challenge_iframe = driver.find_element(
By.XPATH,
"//iframe[@title='Verification challenge']"
)
driver.switch_to.frame(verification_challenge_iframe)
authenticate_button = driver.find_element(
By.XPATH,
"//input[@name='fc-token']"
)
if authenticate_button:
authenticate_value = authenticate_button.get_property('value')
public_key = re.findall(r'\|pk\=([^\|]+)', authenticate_value)[0]
surl = re.findall(r'\|surl\=([^\|]+)', authenticate_value)[0]