Python项目中调试执行单文件的注意点

有时候 ,我们在一个python项目做单文件调试的时候,会发现想单独执行某个文件,但是直接执行的话,会导致module not found 问题,这些文件从系统的path路径找不到,程序的引入文件,所以在这个时候,需要用到sys这个库。

你需要让代码告诉编译器,我引入的自定义的库文件在哪里,所以 一般的解决方案:

import sys

sys.path.append(‘./pathfile’)

#pathfile代表程序需要引入文件的相对路径或者绝对路径,

这样编译器就知道除了path以外,还需要去哪里引入库文件。

CentOs如何快速安装Chrome

The Easy Way

Universal Installation Script for RHEL/CentOS 6.X/7.X

All you need to do is run our installer script and you should be good to go.

curl https://intoli.com/install-google-chrome.sh | bash

This will automatically configure and enable the official Google repository, import Google’s signing key, and install the latest google-chrome-stable executable in your path. If you’re on a RHEL 6.X flavor the it will also automatically find and install all of the unmet dependencies that would normally make the installation fail. You can rerun the script whenever you want to grab the latest version of Google Chrome and, if you’re using RHEL 7.X, then you can update the package using yum as you would with any other package.

RHEL/CentOS 7.X

Alternatively, you can add the repository manually if you’re using a 7.X version. If you’re using Amazon Linux AMI then you’re definitely on a 6.X version and need to use the installation script. Otherwise, you can run

cat /etc/redhat-release

and check the output for the version number to confirm that you’re using 7.X. For example, if you’re using RHEL 7.0 then you would expect to see something like:

Red Hat Enterprise Linux Server release 7.0 (Maipo)

You can use the official Google repository if you see a 7.X version there. To add it to your system, simply create a file called /etc/yum.repos.d/google-chrome.repo with the following contents.

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

Then you just need to run

sudo yum install google-chrome-stable

to install the Chrome package. This will add the google-chrome-stable script in /usr/bin/. Note that this is the same thing that the installation script does on 7.X flavors, so it’s safe to use the script regardless of which version you’re on.

Selenium如何定位到canvas以及如何单击canvas上的元素

最近在做一个自动化的上传项目,碰到了Selenium需要点击canvas上的元素关闭网页蒙层的问题? 想了好久一直没有解决,在网上搜索和实践,终于找到解决方法。

1.定位canvas

这个比较简单,有很多方法,比如 find_element_by_id()

2.点击canvas中的元素,关闭蒙层

这里需要用到 ActionChains 这个类,它是继承selenium.webdriver这个父类,

使用方法也比较简单,主要是操作鼠标,移动到那个关闭按钮的坐标上

ActionChains(driver).move_to_element_with_offset(canvas,590,190).click().perform()

这里做下简单的解释,driver是浏览器的实例,move_to_element_with_offset() 通过相对定位找到元素,canvas是这个canvas画布,click()是鼠标的单击操作,perform()是执行操作,590是元素到左边边框的距离,190是元素到顶部边框的距离。

这样一行命令就完美解决了问题,关闭了网页上的canvas蒙层!

给出参考链接: https://www.pythonf.cn/read/99311