Click on path under svg element | Selenium Python Forum
S
Sambhav Puri Posted on 09/04/2021

Hi,

I want to click on an element path under svg. I am using the xpath //*[@id="buttonname"]/span[1]/svg/path to click on the element.

However it is not able to interact with it.

 

Following is the html. How can I interact with the element?

 

<body>
	<div id="root">
		<div>
			<div>
				<header class="headerclass">
					<div class="firstdivclass">
						<button class="buttonclass" tabindex="0" type="button" id="buttonname" aria-label="menu">
							<span class="firstspanclass">
								<svg class="svgclass" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
									<path d="path"></path>
								</svg>
							</span>
							<span class="secondspanclass"></span>
						</button>
						<h5 class="h5class">Name</h5>
					</div>
				</header>
			</div>
			<div class="seconddivclass"></div>
			<div class="thirddivclass">
				<div class="fourthdivclass">
					<h6 class="h6class">Welcome</h6>
				</div>
			</div>
		</div>
	</div>
	<script src="jspath"></script>
</body>

0
09914040666 Replied on 12/04/2021

Hey, 

What is the exception coming?


S
Sambhav Puri Replied on 12/04/2021

It was that the element //*[@id="buttonname"]/span[1]/svg/path is not found


S
Sambhav Puri Replied on 12/04/2021

I found the solution. I had to modify the xpath to:

//*[@id="buttonname"]/span[1]/*[name()="svg"][@class="svgclass"]


0
09914040666 Replied on 14/07/2021

Hey, 

Thank you for the update. For future if anything like this happens,  you may use the tools available for xpath creation.