如何使用Python+;在JavaScript中获取href值;硒
在上面的HTML中,我想获得值如何使用Python+;在JavaScript中获取href值;硒,python,selenium,Python,Selenium,在上面的HTML中,我想获得值“INC3000…”。 但是如果我使用get_attribute()返回的值是None,因为它在运行时在JavaScript中呈现 如何获取href=javascript:(inc3000004609(新))?您需要使用显式等待结果就绪。不等待就无法获取JS呈现元素。既不是简单的请求,也不是不等待的selenium wait = WebDriverWait(driver, 10) element = wait.until(element_has_text(By.XP
“INC3000…”
。
但是如果我使用get_attribute()
返回的值是None,因为它在运行时在JavaScript中呈现
如何获取href=javascript:(inc3000004609(新))?您需要使用显式等待结果就绪。不等待就无法获取JS呈现元素。既不是简单的请求,也不是不等待的selenium
wait = WebDriverWait(driver, 10)
element = wait.until(element_has_text(By.XPATH, '//a[contains(@class, "btn")]'))
class element_has_text(object):
def __init__(self, locator, css_class):
self.locator = locator
def __call__(self, driver):
element = driver.find_element(*self.locator) # Finding the referenced element
if element.text:
return element
else:
return False
使用稍多的outerHTML更新问题,以便可以唯一标识文本为
inc3000004609
的元素。