无法使用Selenium和Python连接到网页

用户名

我正在尝试连接到特定的网页,但是它没有单击Login按钮:

browser.get('https://www.tsago.gr/eshop/account')
print('Browser Opened')
username = browser.find_element_by_id('email')
username.send_keys(email)
password = browser.find_element_by_id('password')

password.send_keys(pwd)
time.sleep(2)
sing_in = browser.find_element_by_xpath('//*[@class="btn btn-primary"]')
sing_in.click()
print('Login Clicked')

我试图通过css,按名称等查找元素,但是我不知道为什么不单击按钮才能登录

html部分如下

<div class="span3 float-right" style="float:right;">                                   
   <button type="submit" class="btn btn-primary">Connect</button>
</div>

用户名和密码已正确输入

DebanjanB

看来您很亲密。Cookies消息栏可能是障碍,您可以接受cookie或将“连接”按钮滚动到视图中,然后可以使用以下解决方案:

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    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-extensions")
    # options.add_argument('disable-infobars')
    browser = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    browser.get('https://www.tsago.gr/eshop/account')
    print('Browser Opened')
    WebDriverWait(browser, 30).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input#email[name='email']"))).send_keys("Nikos")
    browser.find_element_by_css_selector("input#password[name='password']").send_keys("Nikos")
    browser.execute_script("window.scrollBy(0,250)", "");
    browser.find_element_by_css_selector("div.control-group div.span3 button.btn.btn-primary").click()
    print('Login Clicked')
    
  • 控制台输出:

    Browser Opened
    Login Clicked
    
  • 浏览器快照:

饼干

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法使用 pyodbc 和 SQLAlchemy 通过 Python 连接到 MySQL

BlackBerry无法使用HTTPS连接到某些网页

使用 Selenium 和 Python 访问网页时,Selenium 无法单击元素

无法使用和连接到 MongoDB

无法使用 Python 连接到 BigQuery - ServiceUnavailable

无法在使用 selenium 和 python 的网页抓取期间识别唯一元素

使用python和selenium连接到phantomJs Webdriver时出现问题

Python Selenium无法连接到Webdriver Firefox扩展

selenium.common.exceptions.WebDriverException:消息:无法通过Selenium Python使用ChromeDriver Chrome连接到服务错误

android-使用Jsoup连接到网页

WebDriverException:java.net.ConnectException:在MacOS上使用Selenium 3和chromedriver无法连接到本地主机错误

org.openqa.selenium.firefox.NotConnectedException:使用GeckoDriver和Firefox执行代码时无法连接到主机127.0.0.1

python paho mqtt无法使用用户名和密码连接到mqtts

无法使用JDBC和Spring连接到MySQL

无法使用 Go 和 pq 连接到 postgresql

无法使用 Flask 和 Nameko 连接到 RabbitMQ

无法使用Vagrant和Ubuntu连接到localhost:8080

无法使用Spring Boot和Hibernate连接到Oracle

无法使用ssl和apache连接到websocket

使用 Selenium 和 Python 查找网页上的所有元素

使用python和selenium截取部分网页的截图

如何使用 Selenium 和 Python 从 youtube 上抓取网页

Selenium 网格无法连接到集线器

无法从 Python 连接到 RabbitMQ

无法从网页获取连接到不同参展商的链接

无法使用 python 请求模块连接到 url

无法使用 python 连接到 Azure SQL Server

无法使用python和beautifulsoup抓取网页中的某些href

org.openqa.selenium.WebDriverException:断开连接:使用ChromeDriver未连接到DevTools错误Chrome使用Selenium和Java