如何在表中定位元素

2024-10-02 00:38:34 发布

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

我试图自动化salesforce,但我有一些定位器的问题。我正在使用Python和seleniumwebdriver来实现这一点。你知道吗

我正在尝试单击此元素(给定的代码段):

< th scope = "row" class = " dataCell cellCol1 " > < a href = "javascript:srcUp(%27%2F0019E00000SLiUQ%3FsrPos%3D0%26srKp%3D001%26isdtp%3Dvw%27);" data - seclke = "Account" data - seclkh = "73556054e04c9691f20b5b34809356fd" data - seclki = "0019E00000SLiUQ" data - seclkp = "/0019E00000SLiUQ" data - seclkr = "1" onmousedown = "searchResultClick.mousedown(this, event)" > Harris Kemp < /a></th >

但是,由于某种原因,它找不到它。你知道吗

我在网上找到了不同的解决方案,但似乎都不管用。你知道吗

这是我的密码:

driver.switch_to.frame(1)
    # driver.switch_to.frame(driver.find_element_by_id("history-iframe"))
    # mouseDown() // i entered the location of the element here
    # pyautogui.click() // i entered the location of the element here 

我尝试了另一种方法:

    elem = driver.find_element_by_xpath("//a[@data-seclkr='1']")
    driver.execute_script("arguments[0].click();", elem)

我已经使用了所有不同的xpath,它仍然不会点击它。你知道吗

如果有人能帮忙的话,我会非常感激的。你知道吗

I have attached the full html body image here


Tags: ofthetodatabyheredriverlocation
2条回答

要定位“Edit”元素,可以执行以下操作:

elem1= driver.find_element_by_xpath("//td[@class='actionColumn']")
elem1.find_element_by_xpath(".//a[@class='actionLink']").click()

如果要单击“Harris Kemp”,请尝试:

elem1= driver1.find_element_by_xpath("//th[@scope='row']")
elem1.find_element_by_xpath(".//a[@data-seclke='Account' and text()='Harris Kemp']").click() 

你能从网站上挑选一个简单的标签并尝试下面的方法吗?你知道吗

假设这是HTML脚本:

<div id='a'>
  <div>
    <a class='click'>abc</a>
  </div>
</div>

python脚本应该是:

driver.find_element_by_xpath("//div[@id='a']//a[@class='click']")

输出应为:

<a class="click">abc</a>

然后尝试将.click()放在python代码的末尾

相关问题 更多 >

    热门问题