Clicking On Javascript Tab Using Selenium And Python Without Unique Class Id Or Element Name
Solution 1:
The element with text as Problem is a JavaScript enabled element so to click()
on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:
Using
XPATH
A:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='TabsViewPort']//dl[@class='OuterOuterTab']//dd[@class='OuterTab']//a[@class='btn f1' and text()='Problem']"))).click()
Using
XPATH
B (shortened):WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn f1' and text()='Problem']"))).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
Solution 2:
If the element present inside an iframe then you need to switch to iframe first to access the element.
You can Use following method to frame_to_be_available_and_switch_to_it
()
By locator ID
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"id of the iframe")))
OR
By locator NAME
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"name of the iframe")))
Once You have switched to iframe you can access the element using following xpath
To click on the element Induce WebDriverWait
and element_to_be_clickable
()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//span[@class='Tab']//a[text()='Problem']"))).click()
You need to import following to execute above code.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Hope this will help.
Solution 3:
please find below xpath to click on third TAB
(//span[@class="Tab"])[3]/a
Post a Comment for "Clicking On Javascript Tab Using Selenium And Python Without Unique Class Id Or Element Name"