【问题标题】:What is required to pass URL as arguments in selenium python在 selenium python 中将 URL 作为参数传递需要什么
【发布时间】:2019-11-14 05:07:49
【问题描述】:

我正在编写一个用于自动化的 selenium python 脚本。想要将 IP 作为参数传递以创建要在脚本中使用的 URL。

node_ip = sys.argv[1]
app_url = str("https//"+node_ip+":5200/admin/")
def site_login():
    browser.get(app_url)

但是当我运行脚本时出现以下错误:

# python3 test.py 192.168.20.10
  File "test.py", line 81, in <module>
    site_login()
  File "test.py", line 33, in site_login
    browser.get(app_url)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
  (Session info: headless chrome=78.0.3904.97)

你能帮忙解决这个问题吗?

【问题讨论】:

  • 乍一看str("https//"+node_ip+":5200/admin/")应该是str("https://"+node_ip+":5200/admin/")
  • 您可能最好使用格式化字符串而不是强制整个内容为str。类似f'http://{node_ip}:5200/admin''http://{}:5200/admin'.format(node_ip)
  • print(app_url) 在您尝试使用它进行导航之前......它会打印什么?您应该花一些时间学习如何进行一些基本的调试。
  • @jayg_code:谢谢。 f'http://{node_ip}:5200/admin' 工作。

标签: python python-3.x selenium selenium-webdriver


【解决方案1】:

尝试在 Python 中使用f'http://{node_ip}:5200/admin' 或任何字符串格式化方法。就个人而言,我没有看到太多使用str() 的示例,除非将非字符串变量转换为字符串(即f'I counted {str(x)} times!')。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    相关资源
    最近更新 更多