I'm working on a script to download a textbook from a pdf site, however, when trying to enter the book into the search bar i get an error
selenium.common.exceptions.ElementNotInteractableException: Message: The target element is not interactable and could not be clicked
I've tried to solve this by using EC.element_to_be_clickable((By.XPATH, "//input[@type='text']"))
and using time.sleep(4)
nothing has worked, the search bar is in view as soon as the page loads, I tried using an additional time.sleep() for extra time to load, but it still says the element isn't interactable when it's right there
this is the code
driver.switch_to.new_window('tab')
driver.get('https://www.pdfdrive.com')
time.sleep(2)
driver.fullscreen_window()
# time.sleep(4)
EC.element_to_be_clickable((By.XPATH, "//input[@type='text']"))
bkSrch = driver.find_element(By.XPATH, "//input[@type='text']")
bkSrch.send_keys(bookLnk)
time.sleep(2)
bkSrch.send_keys(Keys.SPACE bookRthr)
`
I also tried clicking the element first and it still doesn't work
I have no other idea of what to do
CodePudding user response:
EC.element_to_be_clickable((By.XPATH, "(//input[@type='text'])[2]"))
bkSrch = driver.find_element(By.XPATH, "(//input[@type='text'])[2]")
bkSrch.send_keys(bookLnk)
wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,".fas.fa-times"))).click()
time.sleep(2)
bkSrch.send_keys(Keys.SPACE bookRthr)
Just click the popup like so also your text search bar was using the wrong input tag.
CodePudding user response:
Try this:
driver.get('https://www.pdfdrive.com')
time.sleep(2)
form = driver.find_element(by=By.ID, value='form-container')
inp = elem.find_element(by=By.TAG_NAME, value="input")
search_query = "it is working!"
driver.execute_script(f"arguments[0].value='{search_query}';", inp)
You can run javascript code in these cases.
For the popup, you can try waiting for 5-10 seconds first (time.sleep(5)) and then search for the close button if exists (use try-except) and if it is there, simply find the close button and click it.