I am new to Selenium and I have been having a problem, I am trying to extract the the title "ferric maltol" as string, here:
https://meshb.nlm.nih.gov/record/ui?ui=C062088
But I have been having lots of troubles with this.
Using the xpath in Python with several different attempts, but none work:
- First attempt
to_store=driver.find_elements_by_xpath('/html/body/div[2]/h1/text()').get_attribute('textContent')
*** selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "/html/body/div[2]/h1/text()" is: [object Text]. It should be an element.
- Second attempt
to_store=driver.find_elements_by_xpath('/html/body/div[2]/h1/text()').text
*** selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "/html/body/div[2]/h1/text()" is: [object Text]. It should be an element.
- Third attempt
to_store=driver.find_elements_by_xpath('/html/body/div[2]/h1/text()').get_attribute('outerHTML')
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "/html/body/div[2]/h1/text()" is: [object Text]. It should be an element.
Does anyone have a clue?
//h1xpath selector should work:to_store=driver.find_element_by_xpath("//h1").text