what i try to do here is get email code for verification. so I log in to the email, select and copy the 6 digits code from the email and paste it to the other tab. everything is done except i can not double click to select the 6 digit code and copy it to clipboard. the code is between h2 tag and nothing else, like this: 639094 where 639094 is actually the code which i need to be copied. how can i find the code element or whatever and copy it? here is a screen shot of the email and the chrome inspect element if anything helps.
this is the code that I use to copy the code:
codeID = driver.find_element(By.XPATH,
'//table[@]//tr//td//p//h2').text
ActionChains = ActionChains(driver)
ActionChains.double_click(codeID).perform()
time.sleep(2)
codeID.send_keys(Keys.CONTROL 'c')
text = pyperclip.paste()
print(text)
CodePudding user response:
Hey i will analyse this problem with you For the first part :
- try to take that XPath you have and past it in the Xpath helper (google chrome extension) => If you find that element , than the problem in your code => if you don’t than the element is already in a frame or in a table The solution is to change your drive to the new frame and relocate the element inside the frame Exemple :
iframe_xpath = driver.find_element_by_xpath('//iframe')
driver.switch_to.frame('iframe_xpath') Now try to relocate the element starting from the iframe
For the second part : You say it’s a table so you need to mention the /td[i] and /tr[j] value where the number is located so you can get it Exemple
d = driver.find_element_by_xpath( "//tr[i]/td[j]").text
I hope that’s help

