【问题标题】:How can I find this element by 'link_text'?如何通过“link_text”找到这个元素?
【发布时间】:2021-09-24 00:59:00
【问题描述】:

我正在编写一个代码,它可以使用 Selenium + BS4 在 Amazon Seller Central 上自动化一些流程。 我想通过链接文本找到一个元素,但它不起作用,, red rectangle is the part that I want to find by link text

我可以通过类名或 xpath 找到元素,但找不到带有链接文本的相同元素。 我需要通过链接文本查找元素,因为我将使用帐户名称作为我同事的变量。 the link text in the tag and the rectangle on the left side has same text

customer = "variable for my cowrkers"
browser.find_element_by_class_name('dropdown-button').click()
browser.find_element_by_xpath('//*[@id="partner-switcher"]/div/button').click()
time.sleep(7)

###### problem
elem = browser.find_elements_by_link_text(customer).click()
print(elem)

我需要帮助:(

【问题讨论】:

标签: python selenium beautifulsoup automation amazon


【解决方案1】:

你可以试试xpath

find_element_by_xpath("//div[@class='picker-name' and text() = 'account text']")

所以,

find_element_by_xpath("//div[@class='picker-name' and text() = '" + customer + "']")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 2019-05-22
    • 1970-01-01
    • 2017-03-14
    • 2022-01-17
    • 1970-01-01
    • 2020-11-19
    相关资源
    最近更新 更多