使用Selenium在网页中显示文本时的Python条件

乔什·米勒(Josh Miller)

我试图确定网页上是否存在文本,然后转到所需的网址。我试图为此编写代码,但不幸的是,我的代码无法正常工作,并在运行代码时给出了无效的语法错误。我在下面使用的代码。我的代码有什么问题?

import re
import selenium.webdriver as webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.keys import Keys
from time import sleep
import random
from selenium import webdriver
import time
from selenium.common.exceptions import NoSuchElementException

    browser = webdriver.Firefox()
    browser.get('https://www.instagram.com/liyanakasini')
    if(browser.findElement(By.xpath(".//*[@id='react-root']/section/main/article/div/h2")).getText().equalsIgnoreCase("This Account is Private")):
    {
        browser.get('http://google.com')
    }

    else
    {
        browser.get('http://yahoo.com')
    }
托马斯·尼尔森

您的代码在不应该缩进的情况下会缩进。而且python{}不像其他语言那样使用在担心硒之前,我建议您先阅读一份python教程。

https://docs.python.org/3/tutorial/index.html

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章