我的网页上有两个具有相同类名的元素,我正在尝试访问第二个元素,但我无法做到这一点。我尝试了 [position=1] 并将 [1] 放在我的 xpath 表达式的末尾
driver.find_element_by_xpath("//div[@class='tableType value']")
Run Code Online (Sandbox Code Playgroud)
以上返回以下2个元素
我试过
driver.find_element_by_xpath("//div[@class='tableType value']")[1]
driver.find_element_by_xpath("//div[@class='tableType value'][position=1]")
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?
谢谢
我对编码很新 - 我们正在使用Selenium和python脚本.
请找到我页面的HMTL的附加屏幕截图.
实际网页是一个表,其中包含所有用户帐户的"x".
我试图找到包含我作为变量传递的用户帐户的href属性.(在下面的示例中,我尝试单击具有"expample@exampleemail.com"的链接)
有人可以帮我找到元素.
谢谢!
我试图找到一组元素,然后点击每个元素,它将我带到一个新页面并在该新页面上执行一些步骤.然后单击浏览器上的后退按钮或新页面上的一个按钮,将我带到上一页,然后找到相同的元素,并对其余元素重复上述过程.
我在继续查找元素之前使用下面的代码再次查找元素,但我的代码不起作用.有人可以帮忙吗?
elements = driver.find_elements_by_css_selector("#top-tables-chart-container > div > svg > g > g > rect")
counter = 0
for counter in range(counter, len(elements)):
elements = driver.find_elements_by_css_selector("#top-tables-chart-container > div > svg > g > g > rect")
webdriver.ActionChains(driver).move_to_element(elements[counter]).click().perform()
time.sleep(5)
tableNameLink= elements[counter].find_element_by_xpath("//div[@class='d3-tip bar-chart top-tables-tooltip n']//div[@class='left-section']//div[@class='table-name']//a[contains(@href,'#/table/')]")
print tableNameLink
tableNameLink.click()
tableName = driver.find_element_by_xpath("//div[@class='discover-design-transform-container clearfix']//div[@class='left-header-section clearfix']//div[@class='entity-info table-type']//span[@class='entity-identifier']")
table = tableName.text
print " Table: " + table
print '\n'
if table == "lineitem":
TableAccessFreqChartInfoBadgesValidation(self.driver).test_table_access_freq_chart_info_badges_validation("F","8","13","13")
time.sleep(1)
print '\n'
if table == "orders":
TableAccessFreqChartInfoBadgesValidation(self.driver).test_table_access_freq_chart_info_badges_validation("D","4","9","9")
time.sleep(1)
print '\n'
topUsagePatternsTab …Run Code Online (Sandbox Code Playgroud)