如何在没有任何错误的情况下按 selenium python 中的 enter?
how to press enter in selenium python with out any error?
我想在 Instagram 中搜索一个特殊的关键词。比如我要搜索这个词:"internet"。我可以在搜索框中发送此密钥。但是,当我通过 Python3 在 Selenium 中使用提交方法时,它不起作用并给我错误。这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Firefox()
url="https://www.instagram.com/p/pTPI-kyX7g/?tagged=resurant"
driver.get(url)
#login_button=driver.find_element_by_xpath("""/html/body/span/section/main/article/div[2]/div[2]/p/a""")
#login_button.click()
import time
driver.implicitly_wait(5)
search_button=driver.find_element_by_xpath("""/html/body/span/section/nav/div[2]/div/div/div[2]/input""")
search_button.send_keys("internet",Keys.RETURN)
这不是任何错误,但它不起作用。
你试过了吗
searchbox driver.find_element_by_xpath( Xpath/locator for search box).sendKey("internet")
search button driver.find_element_by_xpath(Xpath/locator for the search key button).click
你首先将 "internet" 发送到那个编辑框,然后寻找那个搜索按钮并执行 .click
不输入搜索文本并同时发送密钥
请使用此解决方案:
time.sleep(5)
search_button.send_keys(u'\ue007')
search_button.send_keys(u'\ue007')
通过此代码将按下 enter,但是,按下并加载页面后将发生错误:
search_button.send_keys("internet")
while True:
search_button.send_keys(u'\ue007')
我想在 Instagram 中搜索一个特殊的关键词。比如我要搜索这个词:"internet"。我可以在搜索框中发送此密钥。但是,当我通过 Python3 在 Selenium 中使用提交方法时,它不起作用并给我错误。这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Firefox()
url="https://www.instagram.com/p/pTPI-kyX7g/?tagged=resurant"
driver.get(url)
#login_button=driver.find_element_by_xpath("""/html/body/span/section/main/article/div[2]/div[2]/p/a""")
#login_button.click()
import time
driver.implicitly_wait(5)
search_button=driver.find_element_by_xpath("""/html/body/span/section/nav/div[2]/div/div/div[2]/input""")
search_button.send_keys("internet",Keys.RETURN)
这不是任何错误,但它不起作用。
你试过了吗
searchbox driver.find_element_by_xpath( Xpath/locator for search box).sendKey("internet")
search button driver.find_element_by_xpath(Xpath/locator for the search key button).click
你首先将 "internet" 发送到那个编辑框,然后寻找那个搜索按钮并执行 .click
不输入搜索文本并同时发送密钥
请使用此解决方案:
time.sleep(5)
search_button.send_keys(u'\ue007')
search_button.send_keys(u'\ue007')
通过此代码将按下 enter,但是,按下并加载页面后将发生错误:
search_button.send_keys("internet")
while True:
search_button.send_keys(u'\ue007')