send_keys(Keys.ARROW_DOWN)
无效。它在Firefox上完美运行。
如果我这样做
context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()
它应该在右键菜单中选择第二个选项,但它只是执行点击。
在下面的代码中,我想在新标签页中打开链接,但它只是在同一个标签页中打开。
driver = webdriver.Chrome()
driver.get("https://www.google.co.in/?gws_rd=ssl")
driver.maximize_window()
elm_search_wait = WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.ID,"gbqfq")))
elm_search_text = driver.find_element_by_id("gbqfq")
elm_search_text.send_keys("selenium")
bln_content_page = WebDriverWait(driver,10).until(EC.title_contains("selenium"))
blm_result_set = WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,"//ol/div[@class='srg']")))
elm_result_set = driver.find_elements_by_class_name("g")
elm_result_1 = elm_result_set[0]
elm_search_link = elm_result_1.find_element_by_tag_name("a")
ActionChains(driver).move_to_element(elm_search_link)
ActionChains(driver).context_click(elm_search_link).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()
答案 0 :(得分:1)
以下替代可以在 Firefox和Chrome 中使用:
ActionChains(driver).key_down(Keys.CONTROL).click(elm_search_link).perform()
这将模拟链接上的“控制+点击”操作,从而导致其在新标签中打开。