pythonseleniumpubchem

Getting a number from pubchem site with Selenium


I'm doing a search on the pubchem site with the code below. I need to get the "Compound CID:" number from the screen from the search result but I couldn't get it. I need help on this.

driver = webdriver.Chrome()
url = "https://pubchem.ncbi.nlm.nih.gov/"
driver.get(url)
driver.maximize_window()
searchInput = driver.find_element_by_xpath("/html/body/div[1]/div/div/main/div[1]/div/div[2]/div/div[2]/form/div/div[1]/input")
searchInput.click()
searchInput.send_keys("75-05-8")
searchInput.send_keys(Keys.ENTER)
time.sleep(2)
driver.close()

Solution

  • To print the text 6342 you can use either of the following Locator Strategies:


    Ideally you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

    You can find a relevant discussion in How to retrieve the text of a WebElement using Selenium - Python


    References

    Link to useful documentation: