Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 使用Python的Selenium webdriver_Python 2.7_Selenium Webdriver - Fatal编程技术网

Python 2.7 使用Python的Selenium webdriver

Python 2.7 使用Python的Selenium webdriver,python-2.7,selenium-webdriver,Python 2.7,Selenium Webdriver,我需要帮助从标记中获取值。下面是元素及其xpath 要素: <a href="/pages/viewpage.action?pageId=37129112">Sprint1 AC/AT's</a> 代码: 打印xpath返回: selenium.webdriver.firefox.webelement.FirefoxWebElement (session="f680d2ed-7f35-46b2-9f75-c5f27095e39b", element="d5b83487-

我需要帮助从标记中获取值。下面是元素及其
xpath

要素:

<a href="/pages/viewpage.action?pageId=37129112">Sprint1 AC/AT's</a>
代码:

打印xpath
返回:

selenium.webdriver.firefox.webelement.FirefoxWebElement (session="f680d2ed-7f35-46b2-9f75-c5f27095e39b", element="d5b83487-a476-4a00-b470-37668636bdd4")
你能帮我比较一下webelement的字符串吗

  • 如果您想获得单个
    webelement
    ,您应该使用
    find_element_uu…()
    而不是
    find_element_…()
  • 如果需要获取链接文本,应使用
    webelement
    text
    属性:

    sprint="Sprint1"
    
    if sprint in browser.find_element_by_xpath(".//*[@id='content']/div[5]/ul/li/ul/li[2]/ul/li[2]/ul/li[2]/a").text:
        print ("Wow")
    else:
        print ("NotWow")
    
  • selenium.webdriver.firefox.webelement.FirefoxWebElement (session="f680d2ed-7f35-46b2-9f75-c5f27095e39b", element="d5b83487-a476-4a00-b470-37668636bdd4")
    
    sprint="Sprint1"
    
    if sprint in browser.find_element_by_xpath(".//*[@id='content']/div[5]/ul/li/ul/li[2]/ul/li[2]/ul/li[2]/a").text:
        print ("Wow")
    else:
        print ("NotWow")