I am trying to scrape some review data from the Walmart site using Selenium in Python, but it connects this site for human verification. After inspecting this 'Press & Hold' button, somehow when I find the element, it comes out as an [object HTMLIFrameElement], not as a web element. And the element appears randomly inside any of the iframes, among 10 iframes. It can be checked using a loop, but, ultimately we can't take any action in selenium without a web element.
Though this verification also occurs as a popup, I was trying to solve it for this page first. Somehow I located the position of this button using the div
as a webelement.
actions = ActionChains(driver)iframe = driver.find_element_by_xpath("//div[@id='px-captcha']")frame_x = iframe.location['x']frame_y = iframe.location['y']actions.move_to_element(iframe).move_by_offset(frame_x-550, frame_y+70).build().perform()
if I perform a context.click()
or right click, it is visible that mouse position is in the middle of the button.
Now, if I can perform long press or Press & Hold the left mouse button for a while, I guess this verification can be cleared. For this I tried to take action using click()
and click_and_hold
and also with the key_down
methods (as pressing ctrl and enter does the same as long press) in action
, but no response as these methods release the buttons, can't be long pressed. I tried
actions.move_to_element(iframe).move_by_offset(frame_x-550,frame_y+70).click_and_hold().pause(20).perform()actions.move_to_element(iframe).move_by_offset(frame_x-550, frame_y+70).actions.key_down(Keys.CONTROL).actions.key_down(Keys.ENTER).pause(20).perform()
.....and so many ways! How can I solve it using Selenium?