i want to get output from google translator - i don't know how to get a text from from p or span in my case . I already tryed .getText ,.text or .getAttribute("innerhtml").
path = "C:\Program Files (x86)\chromedriver.exe"
opt = Options()
opt.add_experimental_option("debuggerAddress", "Localhost:myport")
driver = webdriver.Chrome(executable_path=path, options=opt)
driver.get("https://translate.google.com/?hl=pl&sl=en&tl=pl&op=translate")
h = driver.find_element_by_xpath("//textarea")
h.click()
h.send_keys("hey")
time.sleep(0.5)
h = driver.find_element_by_xpath(
"//span[@jsaction='click:qtZ4nf,GFf3ac,tMZCfe; contextmenu:Nqw7Te,QP7LD;
mouseout:Nqw7Te; mouseover:qtZ4nf,c2aHje']")
CodePudding user response:
I suggest using the full xpath after sending the text to translate I suggest using:
h = browser.find_element_by_xpath('/html/body/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]').text
I have recently tested this and it worked fine for me.