我使用 PyCharm 右键单击 Run 'hello ' 或使用 shell 运行 python hello.py,都返回以下错误:
if __name__ == "__main__":
^
IndentationError: expected an indented block
下面的代码是从https://selenium-python.readthedocs.io/getting-started.html复制的
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class TestHello(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(
"D:\\Softwares\\selenium\\ChromeDriver 83.0.4103.39\\chromedriver_win32\\chromedriver.exe")
def test_pick_goods(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
print("-----last line----")
def tearDown(self):
#self.driver.close()
if __name__ == "__main__":
unittest.main()
我在if name == " main "之前使用了制表符或四个空格,但都没有效果。
慕斯709654
相关分类