First question: How do I make python minimize chrome?
Second question: When getting to the end page using the next button how do I tell python to go on.. and not give me an error?
driver.get("https://www.google.com/#q=" + user_input)
for n in range(5):driver.find_element_by_xpath("""//*[@id="pnnext"]/span[2]""").click()time.sleep(2)posts2 = driver.find_elements_by_class_name("_Rm")for post2 in posts2:print(post2.text)text_file.write(post2.text + "\n")
After executing this code I get the following error:
Traceback (most recent call last):File "C:/Users/Skid/PycharmProjects/untitled/2nd.py", line 20, in <module>driver.find_element_by_xpath("""//*[@id="pnnext"]/span[2]""").click()File "C:\Users\Skid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 258, in find_element_by_xpathreturn self.find_element(by=By.XPATH, value=xpath)File "C:\Users\Skid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 712, in find_element{'using': by, 'value': value})['value']File "C:\Users\Skid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in executeself.error_handler.check_response(response)File "C:\Users\Skid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_responseraise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="pnnext"]/span[2]"}(Session info: chrome=47.0.2526.111)(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64)