selenium(python)click()方法不使用脚本,但使用commandlin

2024-04-19 22:53:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是python3selenium,我想在https://zomato.com页面中登录,但是当我在脚本中编写并运行它时,登录按钮被单击了,但是对话框没有打开 但当我在命令行(终端)中编写这些语句时,它会被单击,对话框也会打开。 我试过chrome和firefox

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait as wait
import time
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
driver.get("https://www.zomato.com/")
login_btn_outer =driver.find_elements_by_xpath("//*@id='signin-link']")[0].click()

Dialog box not opening

dialog box opening


Tags: fromhttpsimportcomboxsupportbyas
2条回答

事件可能是在页面结构加载之后应用的。 尝试在尝试单击触发器之前等待:

driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS)
driver.get("https://www.zomato.com/")
login_btn_outer =driver.find_elements_by_xpath("//*@id='signinlink']")[0].click()

编辑:我也看了那页。该事件应用于post page ready,其id是signin-link而不是signinlink。你知道吗

试试看这个。这个应该有用。你知道吗

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    options = webdriver.ChromeOptions()
    options.add_argument(" start-maximized")
    options.add_argument(' disable-browser-side-navigation')
    driver = webdriver.Chrome(chrome_options=options, executable_path='D:/Java/TestChrome/lib/chromedriver.exe')
    driver.get("https://www.zomato.com/")
    element=WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, ".//*[@id='signin-link']")))
    element.click() 

让我知道这是否有效。你知道吗

相关问题 更多 >