将带硒的python从mac迁移到pc



对我来说,这应该很直接,但我遇到了一些问题。

我有一些python代码可以在我的mac上完美运行(最新的操作系统py27),但现在我正试图将代码带到我的电脑上进行调度和完全自动化(win8 py27)。

代码如下:

def getElementsByxPath(mydriver,xPath,argKeys):
   try:
       a = mydriver.find_elements_by_xpath(xPath);
       a.send_keys(argKeys) 
       #error caused here. mac handles error on sending keys while it seems windows does not.
       return a;
   except:
       print "Unexpected error:", sys.exc_info()[0];
       return 0;

elem = olrHelper.getElementsByxPath(mydriver, ".//tr[@class='list-item']");
for e2 in elem:
    time.sleep(2)
    tryClick(e2)
    try:
        listingID = e2.get_attribute("data-id") #listingID is populated when I debug
        #additionally e2.is_displayed()==True

        field1 = extractAddress(protectedExtractText(olrHelper.getElementByxPath(mydriver, ".//h1", "")))
        #field1 is not populated and returns my default exception value. very odd.
    except:
        print 'error'

在我的mac上,这个代码是有效的(selenium)。在我的电脑上,这不起作用(硒)。

在PC上找不到xpath元素。

有人经历过类似的事情吗?我以为我会很容易地拥有跨操作系统的功能。

感谢

我的第一个猜测是,问题根本不在于Python代码,而是HTML中的差异,因为它是由不同操作系统上的浏览器"修复"的。换句话说,我怀疑其中一个浏览器正在稍微修改接收到的HTML,以使呈现更容易。我会在这两个文件上"查看源代码"并对其进行WinDiff。

最新更新