使用selenium将python从mac迁移到p

2024-04-20 00:20:14 发布

您现在位置:Python中文网/ 问答频道 /正文

对我来说,这应该是相当直接的,但我有一些问题。你知道吗

我有一些python代码可以在我的mac上完美地运行(最新的OS-py27),但是现在我正试图将这些代码带到我的pc上以进行调度和完全自动化(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元素。你知道吗

有没有人经历过类似的事情?我想我会很容易就拥有跨操作系统的功能。你知道吗

谢谢


Tags: 代码returnismacnoterrorkeysxpath
1条回答
网友
1楼 · 发布于 2024-04-20 00:20:14

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

相关问题 更多 >