Reputation: 125
I am trying to automate a process using Selenium. I almost always use:
driver.find_element_by_xpath('xpath')
to locate the needed elements. As I go through the process, I end up clicking an element that opens a dialog box as such:
https://i.sstatic.net/bCo5K.jpg
The element I am trying to click on looks like this:
https://i.sstatic.net/SLlcy.jpg
The problem is that the xpath and the id are both dynamic, so each time I create a new session, I am dealing with slightly different information.
I located the element by using the following:
driver.find_element_by_xpath('//div[contains(@id, "56$187009")]/div[contains(@class, "gwt")]')
But when I try and send_keys to the element, I get the following error:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
I can see the element on the screen but it seems the driver can not find it. I tried to use:
driver.switch_to_alert()
Upvotes: 1
Views: 339
Reputation: 193218
Try out the following line of code:
driver.find_element_by_xpath("//div[starts-with(@id, '56')][@class='WN5Q WCAR WCU']/input[contains(@class, 'gwt-TextBox WO5Q WBAR')]")
Upvotes: 1