There is a link
<a href="javascript:ga_and_go('//weathernews.jp/s/topics/?fm=onebox', 'topics_more')">…もっと見る</a>
in a html page, I want to click it, I tried code as below, it seems like page can't be parsed, how can I run that function ga_and_go('//weathernews.jp/s/topics/?fm=onebox', 'topics_more')
:
more_button = driver.find_element_by_partial_link_text("…もっと見る")
more_button.click()
Can you try using the below xpath to click the element?
//a[contains(@href,'javascript:ga_and_go(')]
more_button = driver.find_element_by_xpath("//a[contains(@href,'javascript:ga_and_go(')]")
more_button.click()
As per the HTML the element seems to be JavaScript based so you need to induce WebDriverWait and can use either of the following solutions:
Using PARTIAL_LINK_TEXT
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "もっと見る"))).click()
Using XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(.,'もっと見る')]"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.