I'm working on this site drugs.com to see interaction between two drugs . i added two drug name in search box of this site and i need to click on check interactions box in this site to see interaction between two drugs in another window .
I used several methods to solve this problem, but I could not solve this problem. This is my code that add two drugs in search box:
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
# Launch the Chrome browser
driver = webdriver.Chrome()
# Navigate to the drugs.com drug interactions page
driver.get("https://www.drugs.com/drug_interactions.html")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#livesearch-interaction-basic"))).send_keys('aspirin' +Keys.RETURN)
search_box = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#livesearch-interaction")))
search_box.clear()
search_box.send_keys('Aleve')
search_box.send_keys(Keys.RETURN)
HTML snapshot:
To click on the element with text as "Check Interactions" you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using PARTIAL_LINK_TEXT:
Using CSS_SELECTOR:
Using XPATH:
Note: You have to add the following imports :